XRequest请求
XRequest
请求
type XRequestFunction<Input = Record<PropertyKey, any>, Output = Record<string, string>> = (baseURL: string,options: XRequestOptions<Input, Output>,) => XRequestClass<Input, Output>;
| 属性 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| baseURL | 请求接口地址 | string | - | - |
| options | XRequestOptions<Input, Output> | - | - |
| 属性 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| callbacks | 请求回调处理集 | XRequestCallbacks<Output> | - | - |
| params | 请求的参数 | Input | - | - |
| headers | 额外的请求头配置 | Record<string, string> | - | - |
| timeout | 请求超时配置,单位:ms | number | - | - |
| streamTimeout | stream模式的数据超时配置,单位:ms | number | - | - |
| fetch | 自定义fetch对象 | typeof fetch | - | - |
| middlewares | 中间件,支持请求前和请求后处理 | XFetchMiddlewares | - | - |
| transformStream | stream处理器 | XStreamOptions<Output>['transformStream'] | ((baseURL: string, responseHeaders: Headers) => XStreamOptions<Output>['transformStream']) | - | - |
| manual | 是否手动控制发出请求,为true时,需要手动调用run方法 | boolean | false | - |
| 属性 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| onSuccess | 成功时的回调 | (chunks: Output[]) => void | - | - |
| onError | 错误处理的回调 | (error: Error) => void | - | - |
| onUpdate | 消息更新的回调 | (chunk: Output) => void | - | - |
| 属性 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| abort | 取消请求 | () => void | - | - |
| run | 手动执行请求,当manual=true时有效 | (params?: Input) => void | - | - |
| isRequesting | 当前是否在请求中 | boolean | - | - |
type setXRequestGlobalOptions<Input, Output> = (options: XRequestGlobalOptions<Input, Output>,) => void;
type XRequestGlobalOptions<Input, Output> = Pick<XRequestOptions<Input, Output>,'headers' | 'timeout' | 'streamTimeout' | 'middlewares' | 'fetch' | 'transformStream' | 'manual'>;
interface XFetchMiddlewares {onRequest?: (...ags: Parameters<typeof fetch>) => Promise<Parameters<typeof fetch>>;onResponse?: (response: Response) => Promise<Response>;}
Status- |
Update Times0 |
Status- |
Update Times0 |
Status- |
Update Times0 |
Status- |