UNPKG

@spasea/uz-booking-client

Version:
54 lines (53 loc) 2.39 kB
import { Method, AxiosResponse } from 'axios'; /** * Requestable wraps the logic for making http requests to the API */ export default class Requestable { apiBase: string; auth: string; lang: string; userId: string | number; METHODS_WITH_NO_BODY: string[]; /** * Initialize the http internals. * @param {string} [lang] - language * @param {Object} [auth] - the credentials to authenticate to Github. If auth is * not provided request will be made unauthenticated * @param {string} [apiBase] - the base UzBooking API URL * @param {boolean} [langAsApiPrefix] - use language in url as prefix * @param userId */ constructor(lang: string, auth: string, apiBase: string, langAsApiPrefix?: boolean, userId?: string | number); /** * Compute the URL to use to make a request. * @private * @param {string} path - either a URL relative to the API base or an absolute URL * @returns {string} - the URL to use */ getURL(path: string): string; /** * Compute the headers required for an API request. * @private * @param {string} dataType * @param {string} [accessToken] * @returns {Object} - the headers to use in the request */ getRequestHeaders(dataType: any, accessToken: any): any; /** * Make a request. * @param {string} method - the method for the request (GET, PUT, POST, DELETE) * @param {string} path - the path for the request * @param {*} [data] - the data to send to the server. For HTTP methods that don't have a body the data * @param {string} [dataType='json'] - type of data to send * will be sent as query parameters * @param {boolean} [raw=false] - if the request should be sent as raw. If this is a falsy value then the * @param {function(error, data, response)} [callback] - the callback for the request * request will be made as JSON * @returns {Promise<AxiosResponse>} - the Promise for the http request */ request(method: Method, path: string, data: any, dataType?: string, raw?: boolean, callback?: (error: Error, data?: object, response?: object) => any): Promise<AxiosResponse>; private callbackErrorOrThrow; private methodHasNoBody; private formatData; private encodeUrlForm; }