This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Fexios is a lightweight (~6KB gzipped) fetch-based HTTP client library with an axios-like API, targeting both browser and Node.js. Zero runtime dependencies — uses Web APIs only. Requires Node 16.15.0+ or modern browsers.
# Build (parallel: unbuild for ESM/CJS + vite for UMD)
npm run build
# Run all tests
npm run test
# Run a single test file
npx vitest run ./test/core.spec.ts
# Run tests matching a pattern
npx vitest run -t "hook"
# Clean build output
npm run clean
# Preview test coverage report
npm run reviewdist/— ESM (.mjs) and CJS (.cjs) via unbuild, with.d.mtsdeclarationslib/— UMD bundle via vite- Version is injected at build time via
import.meta.env.__VERSION__
The library is built around a hook-based lifecycle that processes requests through sequential stages:
beforeInit → beforeRequest → afterBodyTransformed → beforeActualFetch → afterRawResponse → afterResponse
Each hook can return: void/context (proceed), false (abort), Response (short-circuit fetch), FexiosResponse (short-circuit with parsed response), or FexiosFinalContext (complete context replacement).
Request processing uses a three-layer context structure (FexiosContext):
ctx.request— URL, method, headers, query, body, rawRequestctx.runtime— abortController, customEnv (for passing data between hooks)ctx.response— parsed FexiosResponse (available afterafterRawResponse)
Legacy v5 flat aliases (ctx.url, ctx.headers, etc.) exist on FexiosContext and delegate to ctx.request.* / ctx.runtime.* via property descriptors.
Fexios extends CallableInstance, making instances directly callable: fexios(url, options) calls this.request(). Method shortcuts (get, post, etc.) are defined via Reflect.defineProperty.
src/fexios.ts— Main class: thin orchestration shell (~470 lines), delegates to internalssrc/internals/context.ts— Legacy alias attachment and context finalizationsrc/internals/hooks.ts— Hook execution engine, short-circuit resolution, duck-type checkssrc/internals/request-helpers.ts— URL resolution, body transform, query merge, defaults applicationsrc/types.ts— All type definitions and interfacessrc/models/response.ts—FexiosResponsewrapper with auto-parsed bodysrc/models/errors.ts— Error classes and error code enumsrc/models/header-builder.ts— Static utilities for Headers manipulationsrc/models/query-builder.ts— Static utilities for URLSearchParams
Plugins implement FexiosPlugin interface (name, install, optional uninstall). Built-in plugins under src/plugins/: cookie-jar, sse, ws, post-form. WebSocket and SSE were moved out of core into plugins in v6.
Multiple entry points via exports field in package.json:
fexios— full libraryfexios/core— Fexios class onlyfexios/types— type definitionsfexios/models— response, errors, header/query buildersfexios/utils— callable-instance, deep-merge, clone, isPlainObjectfexios/plugins— all plugins
- Framework: Vitest (configured in
vite.config.tsundertestkey) - Tests are in
test/directory, mock fetch intest/mockFetch.ts - Coverage enabled via
@vitest/coverage-v8, reports to.test_reports/ - Test timeout: 10 seconds
- Path alias:
@/*maps to./src/*
Auto-publish via GitHub Actions (.github/workflows/npm-publish.yml):
- Bump version in
package.json - Commit:
chore: bump version to x.y.z - Create tag:
git tag x.y.z— novprefix - Push:
git push && git push --tags
GitHub Actions will validate that the tag matches package.json version, then build, test, and publish to npm with provenance. Manual trigger via workflow_dispatch is also supported.
- Code comments in English
- Uses
@/path alias for src imports in source code - Static utility classes use namespace pattern (e.g.,
FexiosHeaderBuilder.from()) - Internal markers use Symbols (e.g.,
FINAL_SYMBOLfor context finalization) - Query/header merge priority: request params > URL params > defaults