Comparisons
How is CallApi different from other existing fetching libraries?
Philosophy
Lightweight: Small bundle size (< 3.5kb). Zero dependencies. A pure ESM library.
Simple: Based on the Fetch API and mirrors its interface 1-to-1. Only adds useful extra features with sensible defaults.
Type-safe: Built with TypeScript. Full type support for responses and errors via schemas, validators and manual generics. Even non-TypeScript users will still get proper type information and intellisense. (Automatic type generation via OpenAPI schemas will be available soon.)
Extensible: Plugins and hooks let you add or modify features without changing the core code.
vs Axios
Axios is a popular fetching library, and rightly so since it's been fundamental to development of web applications till date.
But major issues with axios in this day and age involve the facts that:
- It's not based on the modern Fetch API, which is a key part of web development today.
- It's API for some use cases is a bit verbose.
- Lacks advanced convenience features like retries, request deduplication, schema validation, content-type detection etc.
- Lacks / doesn't really care about type safety, which is a real DX problem.
- It's quite on the heavier side, meaning it might not be suitable for smaller projects under a bundle size constraint.
CallApi solves all these problems out of the box, and provides an even larger feature set
vs Ofetch
CallApi is highly inspired by Ofetch. For example, the lifecycle interceptors/hooks idea. As well as the retries and object literal support for the request body.
If you don't need the extra features and convenience options CallApi offers and don't mind the slightly larger bundle size, Ofetch is a good choice since it's also based on the Fetch API.