UNPKG

@openapi-qraft/react

Version:

OpenAPI client for React, providing type-safe requests and dynamic TanStack Query React Hooks via a modular, Proxy-based architecture.

74 lines 3.94 kB
import type { HeadersOptions, OperationSchema, RequestFnInfo, RequestFnOptions, RequestFnResponse } from '@openapi-qraft/tanstack-query-react-types'; /** * This function is used to make a request to a specified endpoint. * * @template T The expected return type of the request. * * @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type. * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc. * @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function. * * @returns {Promise<T>} Returns a promise that resolves with the response of the request. * * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server. */ export declare function requestFn<TData, TError>(schema: OperationSchema, requestInfo: RequestFnInfo, options?: RequestFnOptions): Promise<RequestFnResponse<TData, TError>>; /** * This function is used to make a request to a specified endpoint. * It's necessary to create a custom `requestFn` with a custom `urlSerializer` * and `bodySerializer`, with the tree-shaking of the default `requestFn` * and its serializers. * * @template T The expected return type of the request. * * @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type. * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc. * @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required. * * @returns {Promise<T>} Returns a promise that resolves with the response of the request. * * @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server. */ export declare function baseRequestFn<TData, TError>(requestSchema: OperationSchema, requestInfo: RequestFnInfo, options: WithRequired<RequestFnOptions, 'urlSerializer' | 'bodySerializer'>): Promise<RequestFnResponse<TData, TError>>; /** * Serializes the given schema and request payload into a URL string. * * This function is implemented according to the URI Template standard * defined in RFC 6570. It supports the expansion of path and query parameters, * correctly handling empty arrays, `null`, and `undefined` values by ignoring * them during the expansion process, as specified by the standard. * * For more information, refer to the official documentation: * https://datatracker.ietf.org/doc/html/rfc6570 * * @param schema - The operation schema containing the URL template and method. * @param info - The request payload including baseUrl, path parameters, and query parameters. * @returns The fully constructed URL string. */ export declare function urlSerializer(schema: OperationSchema, info: Pick<RequestFnInfo, 'baseUrl' | 'parameters'>): string; export declare function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]): Headers; export declare function bodySerializer(schema: OperationSchema, body: RequestFnInfo['body']): { body: string; headers: { 'Content-Type': string; }; } | { body: FormData; headers: { 'Content-Type': null; }; } | { body: Blob; headers: { 'Content-Type': string; }; } | undefined; type WithRequired<T, K extends keyof T> = T & { [_ in K]: {}; }; export type { RequestFn, RequestFnResponse, HeadersOptions, RequestFnOptions, RequestFnInfo, OperationSchema, } from '@openapi-qraft/tanstack-query-react-types'; /** * @deprecated use `RequestFnInfo` instead */ export type RequestFnPayload = RequestFnInfo; //# sourceMappingURL=requestFn.d.ts.map