A React fetch utility that wraps the native fetch API with Redux Thunk action dispatching. Version 1.3.5 provides structured error responses as JSON including status, headers, stack trace, and messages. It automatically dispatches request/success/failure Redux actions, with special handling for redirects (3xx), client errors (4xx), unauthorized (401), and server errors (5xx). For development, it supports mocking with configurable success/error rates and simulated delays. The package also sets a CSRF protection cookie (NAV_CSRF_PROTECTION) and a timestamp parameter to prevent browser caching. Ships TypeScript type definitions. Differentiates from plain fetch and other fetch wrappers by tight Redux Thunk integration and development simulation capabilities.
npm install js-fetch-apiNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates defining a Redux Thunk action creator using the call() function from js-fetch-api, including mock configuration with expected payload and error rates for development.
Ensure that expectedErrorRate is not used in production code; it's safe to leave them as they are ignored in production.
Override or disable by not relying on it, or consider using a different fetch wrapper if CSRF cookie behavior is undesirable.
Set cascadeFailureError: true to ensure failure actions are always dispatched for server errors.
Consider using Redux Toolkit's createAsyncThunk instead of this package.
Always provide type: { request: 'SOME/REQUEST', success: 'SOME/SUCCESS', failure: 'SOME/FAILURE' } in every call() invocation.Ensure call() is called with an object parameter that includes url and type.
Make sure the action creator returns call({...}) directly, and the return type is ThunkResult<ActionWithPayload<...>>.Remove expectedErrorRate in production code to avoid confusion, though it's harmless.
Add applyMiddleware(thunk) to your store creation.