Skip to content

Repository files navigation

@arxis/api — type-safe HTTP client for Angular

Stop repeating HttpClient boilerplate. Set your REST API base URL and headers once with provideApi(), then inject(ApiService) anywhere in your Angular app.

npm version npm downloads CI Angular 17+ License: MIT

Open in StackBlitz

@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.

Quick start

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
  }
}

Features

  • Base URL management — Write api.get('users') instead of http.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' and observe: 'events'.
  • Modern Angular — providedIn: 'root', inject(), provideApi() environment providers, standalone apps and NgModules.
  • Multiple APIs — Extend ApiService for each backend, or give a lazy route its own base URL.
  • Uses your HttpClient — Interceptors, withFetch() and HttpTestingController work as usual.
  • Tiny — About 1 KB minified and gzipped.

Documentation

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:

Compatibility

Angular version @arxis/api
17.x and newer ^3.0.0
12.x – 16.x ^1.7.4

Example

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.

Contributing

Bug reports, ideas and pull requests are welcome. See CONTRIBUTING.md for the development setup.

Legacy packages

This repository also has the code of @arxis/fireauth and @arxis/image-processor. They're no longer maintained; see legacy/.

License

MIT © Rene Arias

About

Type-safe Angular HTTP client wrapper — base URL, global headers, inject(ApiService) and provideApi(). Angular 17+

Topics

Resources

Contributing

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages