Fetch Client

Aurelia's @aurelia/fetch-client is a powerful HTTP client built on the native Fetch API, designed specifically for modern web applications. It provides a clean, promise-based interface for making HTTP requests with enterprise-grade features like intelligent caching, automatic retries, and flexible interceptors.

Need real-world patterns? Head over to the fetch-client outcome recipes for guided setups covering auth, caching, and uploads.

import { IHttpClient } from '@aurelia/fetch-client';
import { resolve } from '@aurelia/kernel';

class ApiService {
  private http = resolve(IHttpClient);
  
  async getUsers() {
    const response = await this.http.get('/api/users');
    return response.json();
  }
}

Why Use Aurelia's Fetch Client?

While the native Fetch API is powerful, Aurelia's wrapper adds essential features for real-world applications:

Built for Production

  • Automatic retries with exponential backoff

  • Intelligent caching with background refresh

  • Request/response interceptors for cross-cutting concerns

  • Centralized configuration for consistency across your app

Developer Experience

  • Fluent API with method chaining

  • TypeScript-first with full type safety

  • Dependency injection integration

  • Built-in error handling patterns

Performance Features

  • Request deduplication through caching

  • Background data refresh for stale content

  • Request tracking and status monitoring

  • Minimal overhead over native fetch

Quick Start

Core Features

HTTP Methods

Full support for all HTTP verbs with consistent interfaces:

Request Status Tracking

Monitor your application's network activity:

Smart Base URL Handling

Advanced Capabilities

Intelligent Caching

Reduce server load and improve performance with built-in caching:

Automatic Retries

Handle network failures gracefully:

Powerful Interceptors

Implement cross-cutting concerns like authentication, logging, and error handling:

What's Different from Native Fetch?

Feature
Native Fetch
Aurelia Fetch Client

Error Handling

Only network errors reject

Can reject on HTTP error status

Configuration

Per-request

Centralized with defaults

Caching

Manual implementation

Built-in with multiple strategies

Retries

Manual implementation

Automatic with multiple strategies

Interceptors

None

Request/Response/Error interceptors

JSON Handling

Manual stringify/parse

Helper functions and auto-detection

Base URLs

Manual concatenation

Smart URL resolution

Request Tracking

Manual

Built-in status monitoring

Common Use Cases

API Client Setup:

Authentication Integration:

Form Submissions:

Integration with Aurelia DI

The fetch client is designed to work seamlessly with Aurelia's dependency injection system:

Each service gets its own configured instance when using resolve(IHttpClient), allowing for service-specific configurations while maintaining the global defaults.

Next Steps

The Aurelia Fetch Client transforms the native Fetch API from a low-level primitive into a production-ready HTTP client that scales with your application's needs.

Last updated

Was this helpful?