@xiaohuohumax/x-fetch
Version:
x-fetch package
63 lines (59 loc) • 1.55 kB
TypeScript
/*!
* @xiaohuohumax/x-fetch v0.2.0
* Copyright (c) 2024 xiaohuohumax
* MIT License.
*/
import * as _xiaohuohumax_x_fetch_plugin_retry from '@xiaohuohumax/x-fetch-plugin-retry';
import { RetryPluginOptions } from '@xiaohuohumax/x-fetch-plugin-retry';
import { XFetchOptions as XFetchOptions$1, XFetch as XFetch$1 } from '@xiaohuohumax/x-fetch-core';
export * from '@xiaohuohumax/x-fetch-error';
/**
* The version of the package.
*/
declare const VERSION: string;
/**
* XFetch options.
*/
type XFetchOptions = XFetchOptions$1 & RetryPluginOptions;
/**
* XFetch: A simple, lightweight HTTP request library based on the fetch API, with plugins.
*
* plugins:
*
* - retry: retry failed requests.
*
* Example usage:
*
* ```typescript
* import { XFetch } from "@xiaohuohumax/x-fetch"
* const xFetch = new XFetch({
* baseUrl: "https://example.com",
* retry: {
* enabled: true,
* retries: 3,
* },
* })
*
* // Add a retry interceptor.
* xFetch.request.hook.before("retry", (config) => {
* console.log("before retry", config)
* })
*
* // Add a request interceptor.
* xFetch.request.hook.before("before", (config) => {
* console.log("before request", config)
* })
*
* xFetch.request("GET /api/users", {
* // Request options.
* })
*
* xFetch.request({
* url: "/api/users",
* method: "GET",
* // Request options.
* })
* ```
*/
declare const XFetch: typeof XFetch$1 & (new (...args: any[]) => _xiaohuohumax_x_fetch_plugin_retry.RetryPlugin);
export { VERSION, XFetch, type XFetchOptions };