query/readme.md
2025-06-03 21:12:33 +08:00

955 B

query

对 fetch 功能的的一部分功能的封装。主要处理header的token的提交和response中的处理json。

主要目的:请求路径默认/api/router,使用post,post的数据分流使用pathkey.

适配后端的项目 @kevisual/router

query

const query = new Query();
const res = await query.post({
  path: 'demo',
  key: '1',
});

参数

type QueryOpts = {
  url?: string;
  adapter?: typeof adapter;
  headers?: Record<string, string>;
  timeout?: number;
};
type Data = {
  path?: string;
  key?: string;
  [key: string]: any;
};
// 额外功能
type DataOpts = Partial<QueryOpts> & {
  beforeRequest?: Fn;
};

适配的@kevisual/router的代码

import { App } from '@kevisual/router';
const app = new App();

app
  .route({
    path: 'demo',
    key: '1',
  })
  .define(async (ctx) => {
    ctx.body = 234;
  })
  .addTo(app);