npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@karhoo/demand-api

v20.1.2

Published

The Demand API provides the ability to contact Karhoo's public API and allows you to send and receive network calls and responses.

Downloads

199

Readme

This library provides the ability to contact Karhoo's public API and allows you to send and receive network calls and responses. The Demand API is designed to enable it's consumers to integrate faster because they do not need to create their own complete network stack.

Read The Docs

License

Installation

npm i @karhoo/demand-api

Usage

You can use each service separately, or you can use getApi method which returns all available services

import {
  getApi,
  HttpService,
  LocationService,
  PoiService,
  QuotesV2Service,
  errorCodes,
} from '@karhoo/demand-api'

const url = 'https://public-api.karhoo.com' // please note that there should not be a slash at the end of the url

const correlationIdPrefix = 'prefix'

const requestOptionsGetter = () => ({
  headers: {
    'custom-header': 'Custom header',
  },
})

const middleware = <T>(response: HttpResponse<T>): HttpResponse<T> => {
  console.log(response.status)

  return response
}

Please note that by default fetch will be called with following config

{
  credentials: 'include',
  mode: 'cors',
}

You can override this default settings using defaultRequestOptionsGetter

getApi usage:

All config fields are optional, default value for url - https://public-api.karhoo.com in case if NODE_ENV === 'production', otherwise https://public-api.sandbox.karhoo.com.

Default value for correlationIdPrefix - ''.

Default value for authServiceDefaultOptionsGetter - () => ({}).

const options = {
  url,
  defaultRequestOptionsGetter: requestOptionsGetter,
  authServiceDefaultOptionsGetter,
  responseMiddleware: middleware,
  correlationIdPrefix,
}

const api = getApi(options)

Http service usage:

const apiV1 = 'https://public-api.karhoo.com/v1' // please note that version should be specified

const httpService = new HttpService(url)
  .setCorrelationIdPrefix(correlationIdPrefix)
  .setDefaultRequestOptionsGetter(requestOptionsGetter)
  .setResponseMiddleware(middleware)

const response = await httpService.post('locations/address-autocomplete', { query: 'lond' })

Location service usage:

const locationService = new LocationService(httpService)

Poi service:

const poiService = new PoiService(httpService)

Quotes service:

:warning: QuotesService is deprecated. Please use QuotesV2Service instead

const quotesService = new QuotesV2Service(httpService)

Trip service:

const tripService = new TripService(httpService)

Fare service:

const fareService = new FareService(httpService)

Payment service:

const paymentService = new PaymentService(httpService)

Flags service:

const flagsService = new FlagsService(httpService)

User service:

const userService = new UserService(httpService)

Auth service:

const authService = new AuthService(httpService)

Example

Let's see how to use one of the services, listed above.

For example, you need to get a list of quotes for trip from one location to another. For this purpose you have to use Quotes service and call quotesSearch method:

const quotesSearchParams = {
  origin: {
    latitude: '51.501364',
    longitude: '-0.14189',
    displayAddress: 'Buckingham Palace, London SW1A 1AA',
  },
  destination: {
    latitude: '41.78650',
    longitude: '1.78954',
    displayAddress: 'Big Ben, Westminster, London SW1A 0AA, UK',
  },
  local_time_of_pickup: '2020-05-12T10:00',
}

const quotesResponse = quotesService
  .quotesSearch(quotesSearchParams)
  .then(result => {
    //handleResult
  })
  .catch(error => {
    //handle error
  })

Issues

Looking to contribute?

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior with a label API

💡 Feature Requests

Please file an issue to suggest new features with a label API. Vote on feature requests by adding a 👍. This helps maintainers prioritize what to work on.

❓ Questions

For questions related to using the library, please re-visit a documentation first. If there are no answer, please create an issue with a label help needed and API.

Contributing

License

BSD-2-Clause