UNPKG

@ima/plugin-http-client

Version:

Generic http client for the IMA application framework.

99 lines 3.76 kB
import type { Dependencies } from '@ima/core'; export type RestResourceSettings = { baseApiUrl: string | null; }; declare module '@ima/core' { interface OCAliasMap { '$Settings.plugin.httpClient.rest'?: RestResourceSettings; } } import type { EntityConstructor } from './BaseEntity'; import type { HttpClientRequestOptions } from '../HttpClient'; import { HttpClient } from '../HttpClient'; /** * AbstractResource will help with creating paths to the API as well as working with entities. */ export declare abstract class AbstractResource { #private; static get $dependencies(): Dependencies; /** * PathType is set of constant for use in getter path * @class */ static get PathType(): { GET: string; CREATE: string; UPDATE: string; REPLACE: string; DELETE: string; }; /** * This getter should return paths to API for concrete PathType */ get path(): { [pathType: string]: string; }; /** * Optionally getter for EntityProcessor */ get entityClass(): EntityConstructor | null; constructor(httpClient: HttpClient, settings?: RestResourceSettings); getBaseApiUrl(): string; update<B = any>(data: object, options: HttpClientRequestOptions, pathType?: string): Promise<import("@ima/core").HttpAgentResponse<B> | null>; create<B = any>(data: object, options: HttpClientRequestOptions, pathType?: string): Promise<import("@ima/core").HttpAgentResponse<B> | null>; delete<B = any>(data: object, options: HttpClientRequestOptions, pathType?: string): Promise<import("@ima/core").HttpAgentResponse<B> | null>; get<B = any>(data: object, options: HttpClientRequestOptions, pathType?: string): Promise<import("@ima/core").HttpAgentResponse<B> | null>; replace<B = any>(data: object, options: HttpClientRequestOptions, pathType?: string): Promise<import("@ima/core").HttpAgentResponse<B> | null>; /** * Method invalidate cache for given params * @param method * @param data * @param pathType */ invalidateCache(method: string, data: object, pathType: string): void; /** * Create URL to API by baseApiUrl settings and processed path * * @param pathType * @param data */ getUrl(pathType: string, data: object): string; /** * Prepare data for request * @param data */ prepareData(data: object): {}; /** * Prepare options for request * @param options */ prepareOptions(options: HttpClientRequestOptions): { transformProcessors?: (processor: import("../AbstractProcessor").Processor[]) => import("../AbstractProcessor").Processor[]; timeout?: number | undefined; ttl?: number | undefined; repeatRequest?: number | undefined; fetchOptions?: import("@ima/core").ImaRequestInit | undefined; cache?: boolean | undefined; responseType?: ("json" | "blob" | "text" | "arrayBuffer" | "formData") | undefined; postProcessors?: (<B = unknown>(response: import("@ima/core").HttpAgentResponse<B>) => import("@ima/core").HttpAgentResponse<B>)[] | undefined; abortController?: AbortController | undefined; keepSensitiveHeaders?: boolean | undefined; validateCookies?: boolean | undefined; }; /** * Process path - replace variables by values from data. * * @param pathTemplate * @param data * @private */ processPathTemplate(pathTemplate: string, data: { [key: string]: any; }): string; /** * Returns additionalParams for processors * @param pathType */ getResourceInfo(pathType: string): object; } //# sourceMappingURL=AbstractResource.d.ts.map