aurelia-fetch-client provides a straightforward HTTP client built upon the standard Fetch API, tailored for use within the Aurelia framework ecosystem. It is currently at version 1.8.2 and receives updates with a relatively moderate cadence, primarily for bug fixes and minor feature enhancements. Key differentiators include its seamless integration with Aurelia's dependency injection and plugin system, offering features like request interception, retry functionality (since 1.4.0), and helper methods for common HTTP verbs. While designed for Aurelia, it can function in any JavaScript environment, though a Fetch API polyfill (e.g., `whatwg-fetch`) is often required for broader browser or Node.js compatibility. It ships with TypeScript types, facilitating robust development.
npm install aurelia-fetch-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing HttpClient, configuring a base URL, and performing GET and POST requests with JSON data.
Install `whatwg-fetch` (`npm install whatwg-fetch`) and import it at the application entry point: `import 'whatwg-fetch';`
Review type definitions and ensure proper typing when upgrading. If using JavaScript, be aware of potentially stricter runtime checks in some edge cases introduced by the TS conversion.
Use `json(data)` exclusively for automatically handling JSON serialization and content-type. For other content types or pre-stringified data, set `headers` and `body` directly in `RequestInit`.
If experiencing module resolution issues, ensure your build setup correctly handles native ESM or CommonJS. Upgrading to 1.8.1 or later generally resolves the specific `es2015 back to native-modules` issue.
Install a Fetch polyfill (e.g., `whatwg-fetch`) and import it before `aurelia-fetch-client` usage: `import 'whatwg-fetch';`
Ensure the package is installed (`npm install aurelia-fetch-client`) and that your bundler/runtime is configured to resolve node_modules.
These helper methods were added in version 1.5.0. Upgrade `aurelia-fetch-client` to version 1.5.0 or higher to use them.