amesu
Version:
Node.js SDK for QQ Bot.
44 lines (43 loc) • 1.65 kB
TypeScript
/// <reference types="node" />
type Method = 'GET' | 'DELETE' | 'POST' | 'PUT' | 'PATCH';
type Config = Omit<RequestConfig, 'method' | 'url' | 'body'>;
export declare class RequestError extends Error {
constructor(message: string);
}
export interface RequestConfig extends RequestInit {
method: Method;
url: string;
origin?: string;
}
/** 请求拦截器 */
export type RequestInterceptor = (config: RequestConfig) => RequestConfig | Promise<RequestConfig>;
/** 响应拦截器 */
export type ResponseInterceptor<T = unknown> = (result: Result<T>) => Result | Promise<Result>;
/** 结果集 */
export interface Result<T = unknown> {
data: T;
/** 请求配置项 */
config: RequestConfig;
/** 响应状态码 */
status: number;
/** 状态码消息 */
statusText: string;
/** 请求头 */
headers: Headers;
}
export declare class Request {
private requestInterceptors;
private responseInterceptors;
constructor();
/** 添加请求拦截器 */
useRequestInterceptor(interceptor: RequestInterceptor): void;
/** 添加响应拦截器 */
useResponseInterceptor<T>(interceptor: ResponseInterceptor<T>): void;
basis<T>(config: RequestConfig): Promise<Result<T>>;
get<T>(url: string, params?: object, config?: Config): Promise<Result<T>>;
delete<T>(url: string, params?: object, config?: Config): Promise<Result<T>>;
post<T>(url: string, params?: object, config?: Config): Promise<Result<T>>;
put<T>(url: string, params?: object, config?: Config): Promise<Result<T>>;
patch<T>(url: string, params?: object, config?: Config): Promise<Result<T>>;
}
export {};