Aspida is a TypeScript-friendly HTTP client wrapper designed for both browser and Node.js environments. It streamlines API client generation by enabling developers to define API endpoint types through a convention-over-configuration approach, leveraging a directory structure and `DefineMethods` type aliases. This approach significantly enhances type safety for API interactions at compile time, eliminating the need for manual client creation. Aspida supports integration with popular HTTP clients like Axios, Fetch, and Node-Fetch via official adapter packages. The current stable version is 1.14.0, and the project demonstrates an active release cadence with frequent updates. Its key differentiators include robust type inference for paths, query parameters, headers, request bodies, and responses, comprehensive support for `FormData` and `URLSearchParams`, and a unique workflow that generates a fully type-safe client based on a filesystem-defined API structure.
npm install aspidaVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install Aspida with the Axios adapter, define API endpoints, generate type-safe client code, and make various HTTP requests using the generated client.
Ensure `aspida` is listed in your project's `dependencies` or `devDependencies` (`npm install aspida` or `yarn add aspida`).
Review and update your import paths for generated files (e.g., `../api/$api` might change if the postfix convention affects the top-level generated file directly, or internal generated types). Re-run `npm run api:build` and inspect the generated `$api.ts` file for new import patterns.
Add `"api:build": "aspida"` to your `package.json` scripts and run `npm run api:build` before starting your application development or build process.
Always specify the type of path variables explicitly using the `@type` postfix (e.g., `_id@string`, `_postId@number`) in your API directory structure.
Ensure you have `"api:build": "aspida"` in your `package.json` scripts, then run `npm run api:build`. Verify the import path `../api/$api` matches the location where `aspida` generates the file.
Ensure you are initializing the client correctly with `const client = api(aspida());`. Make sure `@aspida/axios` (or your chosen adapter) is installed and imported as `aspida`.
Double-check your `api` directory structure against how you are accessing the client (e.g., `client.v1.users`). Re-run `npm run api:build` to ensure the client reflects the latest directory definitions.