UNPKG

simplerestclients

Version:

A library of components for accessing RESTful services with javascript/typescript.

43 lines (42 loc) 2.93 kB
/** * GenericRestClient.ts * Author: David de Regt * Copyright: Microsoft 2015 * * Base client type for accessing RESTful services */ import { WebRequestOptions, SimpleWebRequest, WebResponse, Headers } from './SimpleWebRequest'; export declare type HttpAction = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH'; export interface ApiCallOptions extends WebRequestOptions { backendUrl?: string; excludeEndpointUrl?: boolean; eTag?: string; } export interface ETagResponse<T> { eTagMatched?: boolean; response?: T; eTag?: string; } export interface ApiCallResponse<T, TCustomOptions extends {}> { req: SimpleWebRequest<T, ApiCallOptions & Partial<TCustomOptions>>; promise: Promise<WebResponse<T, ApiCallOptions & Partial<TCustomOptions>>>; } export declare class GenericRestClient<TCustomOptions extends {} = {}> { protected _endpointUrl: string; protected _defaultOptions: ApiCallOptions; constructor(endpointUrl: string); protected _performApiCall<T>(apiPath: string, action: HttpAction, objToPost: any, givenOptions?: Partial<ApiCallOptions & TCustomOptions>): ApiCallResponse<T, TCustomOptions>; protected _getHeaders(options: ApiCallOptions & Partial<TCustomOptions>): Headers; protected _blockRequestUntil(options: ApiCallOptions & Partial<TCustomOptions>): Promise<void> | undefined; protected _processSuccessResponse<T>(resp: WebResponse<T, ApiCallOptions & Partial<TCustomOptions>>): void; performApiGet<T>(apiPath: string, options?: ApiCallOptions & Partial<TCustomOptions>): Promise<T>; performApiGetDetailed<T>(apiPath: string, options?: ApiCallOptions & Partial<TCustomOptions>): ApiCallResponse<T, ApiCallOptions & Partial<TCustomOptions>>; performApiPost<T>(apiPath: string, objToPost: any, options?: ApiCallOptions & Partial<TCustomOptions>): Promise<T>; performApiPostDetailed<T>(apiPath: string, objToPost: any, options?: ApiCallOptions & Partial<TCustomOptions>): ApiCallResponse<T, ApiCallOptions & Partial<TCustomOptions>>; performApiPatch<T>(apiPath: string, objToPatch: any, options?: ApiCallOptions & Partial<TCustomOptions>): Promise<T>; performApiPatchDetailed<T>(apiPath: string, objToPatch: any, options?: ApiCallOptions & Partial<TCustomOptions>): ApiCallResponse<T, ApiCallOptions & Partial<TCustomOptions>>; performApiPut<T>(apiPath: string, objToPut: any, options?: ApiCallOptions & Partial<TCustomOptions>): Promise<T>; performApiPutDetailed<T>(apiPath: string, objToPut: any, options?: ApiCallOptions & Partial<TCustomOptions>): ApiCallResponse<T, ApiCallOptions & Partial<TCustomOptions>>; performApiDelete<T>(apiPath: string, objToDelete?: any, options?: ApiCallOptions & Partial<TCustomOptions>): Promise<T>; performApiDeleteDetailed<T>(apiPath: string, objToDelete: any, options?: ApiCallOptions & Partial<TCustomOptions>): ApiCallResponse<T, ApiCallOptions & Partial<TCustomOptions>>; }