UNPKG

create-request

Version:

A modern, chainable wrapper for fetch with automatic retries, timeouts, comprehensive error handling, and first-class TypeScript support

48 lines (47 loc) 2.07 kB
import { get, put, head, post, patch, del, options } from "./requestFactories.js"; import { Config } from "./utils/Config.js"; import { api } from "./apiBuilder.js"; export { HttpMethod, RequestPriority, CredentialsPolicy, RequestMode, RedirectMode, SameSitePolicy, ReferrerPolicy, CacheMode } from "./enums.js"; export type { RetryCallback, RetryConfig, CookiesRecord, CookieOptions, RequestConfig, GraphQLOptions, RequestOptions, ErrorInterceptor, RequestInterceptor, RetryDelayFunction, ResponseInterceptor, } from "./types.js"; export { ResponseWrapper } from "./ResponseWrapper.js"; export { CookieUtils } from "./utils/CookieUtils.js"; export { RequestError } from "./RequestError.js"; export { GetRequest, PostRequest, PutRequest, DeleteRequest, PatchRequest, HeadRequest, OptionsRequest } from "./requestMethods.js"; export { get as createGet, post as createPost, put as createPut, del as createDelete, patch as createPatch, head as createHead, options as createOptions, } from "./requestFactories.js"; export { api as createApi } from "./apiBuilder.js"; /** * Main API object for creating HTTP requests. * Provides factory methods for all HTTP methods and access to global configuration. * * @example * ```typescript * import create from 'create-request'; * * // Simple GET request * const users = await create.get('/api/users').getJson(); * * // POST request with body * const newUser = await create.post('/api/users') * .withBody({ name: 'John', email: 'john@example.com' }) * .getJson(); * * // Configure API instance with defaults * const api = create.api() * .withBaseURL('https://api.example.com') * .withBearerToken('token123'); * * const data = await api.get('/users').getJson(); * ``` */ declare const create: { readonly api: typeof api; readonly get: typeof get; readonly put: typeof put; readonly del: typeof del; readonly post: typeof post; readonly patch: typeof patch; readonly head: typeof head; readonly options: typeof options; readonly config: Config; }; export default create;