General Questions
What is CallApi?
CallApi is a modern, TypeScript-first fetch wrapper that extends the native Fetch API with powerful features like request deduplication, automatic retries, schema validation, and more. It’s designed to solve real problems you encounter in production applications while maintaining a small bundle size (<6KB).Why choose CallApi over other libraries?
CallApi combines the best features from libraries like Axios, Ky, and Ofetch while adding unique capabilities:- Request deduplication with multiple strategies
- Built-in schema validation with automatic type inference
- Extensible plugin system for custom functionality
- Comprehensive TypeScript support with full type inference
- Small bundle size (<6KB) with zero dependencies
- Modern fetch-based API that works everywhere
Is CallApi production-ready?
Yes! CallApi is actively maintained and used in production applications. It follows semantic versioning and has comprehensive test coverage.What environments does CallApi support?
CallApi works in any environment that supports the Fetch API:- Modern browsers (Chrome, Firefox, Safari, Edge)
- Node.js 18+
- Deno
- Bun
- Cloudflare Workers
- Vercel Edge Functions
- Other edge runtimes
Is CallApi free to use?
Yes! CallApi is open source under the MIT license, which means you can use it freely in both personal and commercial projects.TypeScript Questions
Do I need TypeScript to use CallApi?
No! CallApi works perfectly with plain JavaScript. However, TypeScript users get additional benefits like automatic type inference from schemas and better IDE autocomplete.How does type inference work?
CallApi automatically infers types from validation schemas:Can I use CallApi without schema validation?
Yes! You can provide types manually using TypeScript generics:Why do I need to pass false as the second generic sometimes?
When using throwOnError: true or resultMode: "onlyData", you need to signal this to TypeScript:
How do I extend CallApi’s types?
Use module augmentation to extend CallApi’s types:Usage Questions
How do I handle authentication?
Use theonRequest hook to add authentication headers:
How do I upload files?
Use FormData for file uploads:How do I download files?
For small files:How do I cancel requests?
Use AbortController:How do I handle request deduplication?
CallApi automatically deduplicates requests. Choose your strategy:How do I configure retries?
Configure retries at the client or request level:How do I use CallApi with React Query?
Configure CallApi to throw errors and return only data:How do I handle different response types?
Use theresponseParser option:
How do I set custom headers?
Set headers at the client or request level:Schema Validation Questions
What validation libraries are supported?
CallApi supports any library that implements the Standard Schema specification:- Zod - Most popular, excellent TypeScript support
- Valibot - Lightweight and performant
- ArkType - Advanced type-level validation
- Yup - Popular in form validation
- And more!
Do I need to validate every request?
No! Validation is optional. Use it when:- You need runtime type safety
- You want automatic type inference
- You’re working with external APIs
- Data integrity is critical
Can I validate request data?
Yes! Validate body, headers, params, and query:What happens when validation fails?
AValidationError is returned (or thrown if throwOnError: true):
Can I customize validation error messages?
Yes! Most schema libraries allow custom error messages:Plugin Questions
What are plugins?
Plugins extend CallApi with reusable functionality. They can:- Modify requests before they’re sent
- Intercept the fetch call
- Hook into the request lifecycle
- Add custom options
How do I create a plugin?
Use thedefinePlugin helper:
Are there official plugins?
Yes! CallApi includes several official plugins:- Logger Plugin - Request/response logging
- More coming soon!
Can I share plugins across projects?
Yes! Create an npm package with your plugin and install it in multiple projects:Error Handling Questions
What types of errors can occur?
CallApi provides structured errors:- HTTPError - HTTP response errors (4xx, 5xx)
- ValidationError - Schema validation failures
- TimeoutError - Request timeout
- AbortError - Request cancelled
- TypeError - Network errors, invalid URLs
- Other JavaScript errors
How do I check error types?
Use the provided type guards:Should I use throwOnError or return errors?
It depends on your use case:
Return errors (default) when:
- You prefer explicit error handling
- You want to avoid try/catch blocks
- You’re building your own abstraction
- Integrating with React Query or similar libraries
- You prefer exception-based error handling
- You want errors to propagate to error boundaries
How do I access the original Response object?
It’s always available in the result:Performance Questions
Does request deduplication improve performance?
Yes! Request deduplication prevents:- Duplicate network requests
- Wasted bandwidth
- Race conditions
- Unnecessary server load
How does CallApi compare in bundle size?
- CallApi: <6KB minified + gzipped
- Axios: ~13KB
- Ky: ~5KB
- Ofetch: ~8KB
Does CallApi cache responses?
No. CallApi doesn’t implement response caching. For caching, use:- TanStack Query for client-side caching
- HTTP cache headers
- Service Workers
- Custom caching plugins
Can I use CallApi for SSR?
Yes! CallApi works in Node.js 18+ and all edge runtimes:Troubleshooting
Why am I getting TypeScript errors?
Common issues:-
Missing second generic: When using
throwOnError: trueorresultMode: "onlyData", passfalseas second generic: - Schema type mismatch: Ensure your schema matches the actual API response
- Old TypeScript version: CallApi requires TypeScript 4.7+
Why aren’t my requests being deduplicated?
Check that:- Requests are from the same
callApiinstance - Requests have identical URLs and parameters
- Deduplication isn’t disabled (
dedupeStrategy: 'none')
Why aren’t retries working?
Verify:retryAttemptsis set to a number > 0- The HTTP method is in
retryMethods(default:['GET', 'POST']) - The status code is in
retryStatusCodes(if specified) - Your
retryConditionfunction returnstrue(if specified)
Why is validation failing?
Check:- Your schema matches the actual response structure
- All required fields are present
- Field types match (string vs number, etc.)
- Array vs single object mismatch
Getting Help
Where can I get help?
- Documentation: Check the full documentation
- GitHub Issues: Open an issue
- GitHub Discussions: Ask questions in Discussions
How do I report a bug?
Open an issue on GitHub with:- Clear description of the issue
- Minimal reproduction code
- Expected vs actual behavior
- CallApi version
- Environment (browser, Node.js version, etc.)
How do I request a feature?
Open a feature request on GitHub Discussions with:- Clear use case description
- Why existing features don’t solve it
- Proposed API (if you have ideas)
- Examples from other libraries (if applicable)