import { IVResponse } from 'vedavaapi-web'; import { IOpaqueDataInfo } from '../web-utils'; import { IContext, IModelsRegistry } from '../context'; export interface IParams { [param: string]: any; } export interface IResponse
extends IVResponse { data: DT; } export declare type APIMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'; /** * custom Request init params interface; sameas fetch Request's init; * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#Parameters; */ export interface IInit { headers?: { [header: string]: string; }; cache?: RequestCache; credentials?: RequestCredentials; integrity?: string; mode?: RequestMode; redirect?: RequestRedirect; referrer?: string; referrerPolicy?: ReferrerPolicy; [initArg: string]: any; } /** * static class providing interface for API HTTP methods. handles json stringification, formdata computation, search params computation, etc. */ export declare class APIRequest { static get(vc: IContext, url: string, params?: IParams, init?: IInit): Promise>; static post(vc: IContext, url: string, data?: IParams, odInfo?: IOpaqueDataInfo, params?: IParams, init?: IInit): Promise>; static delete(vc: IContext, url: string, data?: IParams, params?: IParams, init?: IInit): Promise>; static put(vc: IContext, url: string, data?: IParams, odInfo?: IOpaqueDataInfo, params?: IParams, init?: IInit): Promise>; /** * * @param vc Context * @param url url * @param method GET | POST | PUT | DELETE * @param data dictionory of body params; * @param params dictionary of query params * @param init custom Request init overridings * @throws APIError */ static request(vc: IContext, url: string, method: APIMethod, data?: IParams, odInfo?: IOpaqueDataInfo, params?: IParams, init?: IInit): Promise>; } export declare type IURLGen = (vc: IContext, urlParts: any) => string; export declare const urlMakerFnFactory: (namespaceBase: string) => (endpoint: string) => IURLGen; export declare type IResponseMiddleware = (data: any, mr?: IModelsRegistry) => T; export interface IEndpointMethodConfig { /** response middleware function for an endpoint method. */ middleware?: IResponseMiddleware; /** Opaque Data Info */ odInfo?: IOpaqueDataInfo; } /** * Configuration for an API Endpoint methods */ export interface IEndpointMethodsConfig { get?: IEndpointMethodConfig; post?: IEndpointMethodConfig; put?: IEndpointMethodConfig; delete?: IEndpointMethodConfig; } /** * Configuration of an api endpoint instance */ export interface IEndpointConfig { /** (better unique) name of endpoint. will be used in error stackTraces, if any. */ name: string; /** params which are components of url path */ urlPartParams?: string[]; /** url generator function for an api endpoint */ url: IURLGen; /** api methods configurations */ methods: IEndpointMethodsConfig; } export interface APIRequestInit { vc: IContext; params?: P; data?: D; init?: IInit; marshal?: boolean; } export interface APIRequestGenericInit extends APIRequestInit { method: APIMethod; } /** * APIEndpoint class; api endpoints are objects of this class, inheriting all it's prototype properties * have to supply appropriate endpoint configuration, to instantiate an endpoint object; * provides methods corresponding to HTTP methods get, post, put, delete * also provides method specific marshaller methods too, so that we can first request pure responses, and then marshal when required. needed in environments where POJOS are needed. */ export declare class APIEndpoint { [x: string]: any; private config; private endpointUrlFn; constructor(config: IEndpointConfig); /** * returns full url computed from params. if required params for a given endpoint are not present, raises APIClientError * @param vc - Context * @param params - params associated with endpont */ url({ vc, params }: { vc: IContext; params?: GP; }): string; private getMethodConfig; marshalResponse(method: APIMethod, response: IResponse, mr?: IModelsRegistry): any; request({ vc, method, params, data, init, marshal }: APIRequestGenericInit): Promise>; get({ vc, params, init, marshal }: APIRequestInit): Promise>; marshalGetResponse(response: IResponse, mr?: IModelsRegistry): IResponse; post({ vc, params, data, init, marshal }: APIRequestInit): Promise>; marshalPostResponse(response: IResponse, mr?: IModelsRegistry): IResponse; put({ vc, params, data, init, marshal }: APIRequestInit): Promise>; marshalPutResponse(response: IResponse, mr?: IModelsRegistry): IResponse; delete({ vc, params, data, init, marshal }: APIRequestInit): Promise>; marshalDeleteResponse(response: IResponse, mr?: IModelsRegistry): IResponse; private computeURLParts; } declare const _default: { APIRequest: typeof APIRequest; APIEndpoint: typeof APIEndpoint; }; export default _default;