/// import IRESTClient, { ErrorResponseHandler, ResponseHandler } from "./IRESTClient"; import ClientResponse from "./ClientResponse"; import { BodyInit, RequestCredentials, Response } from 'node-fetch'; import { URLSearchParams } from "url"; /** * @author Brett P * @author Tyler Scott * @author TJ Peden */ export default class DefaultRESTClient implements IRESTClient { host: string; body: BodyInit; headers: Record; method: string; parameters: Record; uri: string; credentials: RequestCredentials; responseHandler: ResponseHandler; errorResponseHandler: ErrorResponseHandler; constructor(host: string); /** * A function that returns the JSON form of the response text. * * @param response * @constructor */ static JSONResponseHandler(response: Response): Promise>; /** * A function that returns the JSON form of the response text. * * @param response * @constructor */ static ErrorJSONResponseHandler(response: Response): Promise>; /** * Sets the authorization header using a key * * @param {string} key The value of the authorization header. * @returns {DefaultRESTClient} */ withAuthorization(key: string): DefaultRESTClient; /** * Adds a segment to the request uri */ withUriSegment(segment: string | number): DefaultRESTClient; /** * Get the full url + parameter list */ getFullUrl(): string; /** * Sets the body of the client request. * * @param body The object to be written to the request body as form data. */ withFormData(body: URLSearchParams): DefaultRESTClient; /** * Adds a header to the request. * * @param key The name of the header. * @param value The value of the header. */ withHeader(key: string, value: string): DefaultRESTClient; /** * Sets the body of the client request. * * @param body The object to be written to the request body as JSON. */ withJSONBody(body: object): DefaultRESTClient; /** * Sets the http method for the request */ withMethod(method: string): DefaultRESTClient; /** * Sets the uri of the request */ withUri(uri: string): DefaultRESTClient; /** * Adds parameters to the request. * * @param name The name of the parameter. * @param value The value of the parameter, may be a string, object or number. */ withParameter(name: string, value: any): DefaultRESTClient; /** * Sets request's credentials. * * @param value A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */ withCredentials(value: RequestCredentials): DefaultRESTClient; withResponseHandler(handler: ResponseHandler): DefaultRESTClient; withErrorResponseHandler(handler: ErrorResponseHandler): DefaultRESTClient; /** * Run the request and return a promise. This promise will resolve if the request is successful * and reject otherwise. */ go(): Promise>; private getQueryString; }