{"id":15687006,"url":"https://github.com/dragon-fish/fexios","last_synced_at":"2025-04-30T15:03:14.513Z","repository":{"id":181511512,"uuid":"666883000","full_name":"dragon-fish/fexios","owner":"dragon-fish","description":"Fetch based HTTP client with similar API to axios for browser and Node.js / 类似 Axios 语法的原生 fetch API 请求封装库","archived":false,"fork":false,"pushed_at":"2025-04-08T10:19:19.000Z","size":135,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T10:22:47.865Z","etag":null,"topics":["ajax","axios","browser","fetch","fetch-api","hookable","http","node","promise"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dragon-fish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-15T22:51:50.000Z","updated_at":"2025-04-08T10:19:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cf851bf-2522-47a9-af1e-ac6a7a0b8fcd","html_url":"https://github.com/dragon-fish/fexios","commit_stats":null,"previous_names":["dragon-fish/fexios"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragon-fish%2Ffexios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragon-fish%2Ffexios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragon-fish%2Ffexios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragon-fish%2Ffexios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dragon-fish","download_url":"https://codeload.github.com/dragon-fish/fexios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251725931,"owners_count":21633696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajax","axios","browser","fetch","fetch-api","hookable","http","node","promise"],"created_at":"2024-10-03T17:42:28.114Z","updated_at":"2025-04-30T15:03:14.430Z","avatar_url":"https://github.com/dragon-fish.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# Fexios\n\n类 Axios 语法的原生 fetch API 请求封装库\u003cbr\u003e\nFetch based HTTP client with similar API to axios for browser and Node.js\n\n~~fetch + axios = fexios~~ (Just a joke)\n\n\u003c/div\u003e\n\n## 特色功能 Features\n\n- [x] 🤯 Native fetch API (supports the Promise API)\n- [x] 🤫 Method shortcuts (`fexios.post()`)\n- [x] 🔗 Hooks (intercept request and response)\n- [x] 😏 Automatic transform request and response data\n- [x] 😏 Automatic transforms for JSON data\n- [x] 🤩 Instances with custom defaults\n- [x] 🫡 Instance extendable\n- [x] 😍 Fricking tiny size: `index.umd.cjs  8.51 kB │ gzip: 3.48 kB │ map: 31.96 kB`\n\n## 安装 Installation\n\n**包管理器 Using package manager**\n\n```sh\n# Node Package Manager\nnpm install fexios\n# Why not pnpm\npnpm add fexios\n# Or yarn?\nyarn add fexios\n```\n\nThen import the library and enjoy:\n\n```ts\nimport fexios, { createFexios, Fexios } from 'fexios'\n\n// Using directly\nfexios.get('https://zh.moegirl.org.cn/api.php')\n\n// With options\nconst fexios = createFexios(/* options */)\nconst fexios = new Fexios(/* options */)\nconst fexios = Fexios.create(/* options */)\n```\n\n**在浏览器中直接使用 Use directly in the browser**\n\n- JS Module\n\n```ts\nimport('https://unpkg.com/fexios?module').then(({ createFexios }) =\u003e {\n  const fexios = createFexios(/* options */)\n})\n```\n\n- Global variables\n\n```html\n\u003cscript src=\"https://unpkg.com/fexios\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  // Using directly\n  fexios.get('https://zh.moegirl.org.cn/api.php')\n\n  // With options\n  const { createFexios } = Fexios\n  const fexios = createFexios(/* options */)\n\u003c/script\u003e\n```\n\n## 兼容性 Compatibility\n\nRefer: https://developer.mozilla.org/docs/Web/API/Fetch_API\n\n| Chrome | Edge | Firefox | Opera | Safari          | Node.js                |\n| ------ | ---- | ------- | ----- | --------------- | ---------------------- |\n| 42     | 14   | 39      | 29    | 10.1 (iOS 10.3) | ^16.15.0 \\|\\| \u003e=18.0.0 |\n\n\\* Abort signal requires higher version.\n\n## 使用方法 Usage\n\nYou can find some sample code snippets [here](test/).\n\n### new Fexios(configs: Partial\\\u003cFexiosConfigs\u003e)\n\n\u003cdetails\u003e\n\n\u003csummary\u003eFexiosConfigs\u003c/summary\u003e\n\n```ts\nexport type FexiosConfigs = {\n  baseURL: string\n  query: Record\u003cstring, string | number | boolean\u003e | URLSearchParams\n  headers: Record\u003cstring, string\u003e | Headers\n  credentials: 'omit' | 'same-origin' | 'include'\n  responseType: 'json' | 'blob' | 'text'\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eDefaults\u003c/summary\u003e\n\n```ts\nconst DEFAULT_CONFIGS = {\n  baseURL: '',\n  credentials: 'same-origin',\n  headers: {\n    'content-type': 'application/json; charset=UTF-8',\n  },\n  query: {},\n  responseType: 'json',\n}\n```\n\n\u003c/details\u003e\n\n### Fexios#request(config: FexiosRequestOptions)\n\n`fexios.request\u003cT\u003e(config): Promise\u003cFexiosResponse\u003cT\u003e\u003e`\n\n\u003cdetails\u003e\n\n\u003csummary\u003eFexiosRequestOptions\u003c/summary\u003e\n\n```ts\nexport interface FexiosRequestOptions {\n  baseURL?: string\n  method?: FexiosMethods\n  credentials?: 'omit' | 'same-origin' | 'include'\n  headers?: Record\u003cstring, string\u003e | Headers\n  query?: Record\u003cstring, string | number | boolean\u003e | URLSearchParams\n  body?: Record\u003cstring, any\u003e | string | FormData | URLSearchParams\n  responseType?: 'json' | 'blob' | 'text'\n}\n```\n\n\u003c/details\u003e\n\n**returns {FexiosFinalContext}**\n\n```ts\nexport type FexiosFinalContext\u003cT = any\u003e = Omit\u003c\n  FexiosContext\u003cT\u003e,\n  'rawResponse' | 'response' | 'data' | 'headers'\n\u003e \u0026 {\n  rawResponse: Response\n  response: FexiosResponse\u003cT\u003e\n  headers: Headers\n  data: T\n}\nexport type FexiosResponse\u003cT = any\u003e = {\n  rawResponse: Response\n  ok: boolean\n  status: number\n  statusText: string\n  headers: Headers\n  isGood: boolean\n  data: T\n}\n```\n\nAnd common request methods aliases:\n\n- fexios.get(url[, config])\n- fexios.delete(url[, config])\n- fexios.head(url[, config])\n- fexios.options(url[, config])\n- fexios.post(url[, data[, config]])\n- fexios.put(url[, data[, config]])\n- fexios.patch(url[, data[, config]])\n\n## 钩子 Hooks\n\nYou can modify context in hooks' callback then return it as a brand new context™.\n\nReturn `false` to abort request immediately.\n\n```ts\nexport type FexiosHook\u003cC = unknown\u003e = (context: C) =\u003e AwaitAble\u003cC | false\u003e\nexport interface FexiosContext\u003cT = any\u003e extends FexiosRequestOptions {\n  url: string // may changes after beforeInit\n  rawRequest?: Request // provide in beforeRequest\n  rawResponse?: Response // provide in afterRequest\n  response?: FexiosResponse // provide in afterRequest\n  data?: T // provide in afterRequest\n}\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003eHooks example\u003c/summary\u003e\n\n```ts\nconst fexios = new Fexios()\n\nfexios.on('beforeRequest', async (ctx) =\u003e {\n  const url = new URL(ctx.url)\n  if (url.searchParams.has('foo')) {\n    return false\n  } else {\n    url.searchParams.set('foo', 'bar')\n    ctx.url = '' + url\n    return ctx\n  }\n})\n```\n\n\u003c/details\u003e\n\n### beforeInit\n\nAll context passed as is. You can do custom conversions here.\n\n### beforeRequest\n\nPre-converted done.\n\nAt this time, `ctx.url` has been converted to final URL string. You cannot modify the `ctx.query` or `ctx.baseURL` to change `ctx.url`. Please modify `ctx.url` directly.\n\n- `ctx.url` `{string}` full URL string converted from url, baseURL and ctx.query\n- `ctx.query` `{Record\u003cstring, string\u003e}` merged from url, requestOptions, baseOptions\n- `ctx.headers` `{Record\u003cstring, string\u003e}` merged from requestOptions, baseOptions\n\n### afterBodyTransformed\n\nJSON body has been transformed to JSON string. `Content-Type` header has been set to body's type.\n\n- `ctx.body` `{string|URLSearchParams|FormData|Blob}`\n\n### beforeActualFetch\n\nThe Request instance has been generated.\n\nAt this time, you cannot modify the `ctx.url`, `ctx.query`, `ctx.headers` or `ctx.body` (etc.) anymore. Unless you pass a brand new `Request` to replace `ctx.rawRequest`.\n\n- `ctx.rawRequest` `{Request}`\n\n### afterResponse\n\nThe `FexiosFinalContext` will be passed\n\n### interceptors\n\nOh, this is mimicked from axios. Just sweet sugar.\n\n\u003c!-- prettier-ignore-start --\u003e\n```ts\n// They are the same\nfexios.on('beforeRequest', async (ctx) =\u003e {})\nfexios.interceptors.request.use((ctx) =\u003e  {})\n\n// Bro, they're just the same\nfexios.on('afterResponse', async (ctx) =\u003e {})\nfexios.interceptors.response.use((ctx) =\u003e {})\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n---\n\n\u003e MIT License\n\u003e\n\u003e Copyright (c) 2023 机智的小鱼君 (A.K.A. Dragon-Fish)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragon-fish%2Ffexios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragon-fish%2Ffexios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragon-fish%2Ffexios/lists"}