Stop repeating
HttpClientboilerplate. Set your REST API base URL and headers once withprovideApi(), theninject(ApiService)anywhere in your Angular app.
@arxis/api is a small, typed wrapper around Angular's HttpClient for REST APIs. It gives you an ApiService with get, post, put, patch and delete, a base URL you configure once, and headers that go with every request. It uses the HttpClient of your app, so your interceptors, withFetch() and testing tools keep working.
npm install @arxis/api// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import { provideApi } from '@arxis/api';
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
provideApi({
url: 'https://api.example.com',
globalHeaders: { 'X-Api-Key': 'key-123' },
}),
],
};// user.service.ts
import { Injectable, inject } from '@angular/core';
import { ApiService } from '@arxis/api';
@Injectable({ providedIn: 'root' })
export class UserService {
private readonly api = inject(ApiService);
getUsers() {
return this.api.get<User[]>('users'); // GET https://api.example.com/users
}
createUser(body: CreateUserDto) {
return this.api.post<User>('users', body); // POST https://api.example.com/users
}
}- Base URL management — Write
api.get('users')instead ofhttp.get(baseUrl + '/users'). - Global headers — API keys and fixed headers go with every request automatically.
- Type-safe — Generics for response types, plus typed overloads for
observe: 'response'andobserve: 'events'. - Modern Angular —
providedIn: 'root',inject(),provideApi()environment providers, standalone apps and NgModules. - Multiple APIs — Extend
ApiServicefor each backend, or give a lazy route its own base URL. - Uses your
HttpClient— Interceptors,withFetch()andHttpTestingControllerwork as usual. - Tiny — About 1 KB minified and gzipped.
New to @arxis/api? Start with the introduction on dev.to: Stop repeating HttpClient boilerplate in Angular.
The full documentation is in the package README:
- Before and after:
HttpClientcompared withApiService - Configuration: standalone apps, NgModules and
EndPointConfig - Multiple APIs: subclasses and per-route base URLs
- Testing with
HttpTestingController - FAQ: base URLs, headers on every request, auth tokens
- Migrating from 1.x to 3.0
- Changelog
| Angular version | @arxis/api |
|---|---|
| 17.x and newer | ^3.0.0 |
| 12.x – 16.x | ^1.7.4 |
examples/angular-standalone is an Angular 21 app that loads and creates posts on JSONPlaceholder. Open it in StackBlitz to try @arxis/api in your browser.
Bug reports, ideas and pull requests are welcome. See CONTRIBUTING.md for the development setup.
This repository also has the code of @arxis/fireauth and @arxis/image-processor. They're no longer maintained; see legacy/.
MIT © Rene Arias