A type-safe Angular HTTP client library for Strapi v5+ with support for filtering, sorting, pagination, population, and localization.
- Full TypeScript support with generics
- Strapi v5 compatible
- Advanced filtering, sorting, and population
- Built-in pagination and localization support
- Bearer token authentication
npm install angular-strapi-clientimport { ApplicationConfig } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import { STRAPI_CONFIG } from 'angular-strapi-client';
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
{
provide: STRAPI_CONFIG,
useValue: { url: 'https://your-strapi-api.com' },
},
],
};import { Injectable } from '@angular/core';
import { StrapiService, StrapiEntry } from 'angular-strapi-client';
export interface Article extends StrapiEntry {
title: string;
content: string;
}
@Injectable({ providedIn: 'root' })
export class ArticlesService extends StrapiService<Article> {
path = '/articles';
}// Fetch all
this.articlesService.get().subscribe((response) => {
console.log(response.data);
});
// Fetch by numeric ID (legacy)
this.articlesService.get(123).subscribe((response) => {
console.log(response.data);
});
// Create (no ID)
this.articlesService
.save(null, { title: 'New Article' })
.subscribe((response) => console.log(response.data));
// Update (with ID)
this.articlesService
.save('abc123xyz', { title: 'Updated' })
.subscribe((response) => console.log(response.data));
// Delete
this.articlesService.delete('abc123xyz').subscribe();this.articlesService
.get(undefined, {
filters: {
title: { $contains: 'Angular' },
publishedAt: { $notNull: true },
$or: [{ category: { name: { $eq: 'Tech' } } }],
},
})
.subscribe((response) => console.log(response.data));Available operators: $eq, $ne, $lt, $lte, $gt, $gte, $in, $notIn, $contains, $containsi, $startsWith, $endsWith, $null, $notNull, $between, $or, $and, $not.
For more details see this page: Strapi filters
You can sort one or more fields. Sorting order can be defined by operators:
- :asc - for ascending (default, can be omitted)
- :desc - for descending
// Single field
this.articlesService
.get(undefined, {
sort: 'title',
})
.subscribe((response) => console.log(response.data));
// Multiple fields
this.articlesService
.get(undefined, {
sort: ['publishedAt:desc', 'title:asc'],
})
.subscribe((response) => console.log(response.data));// All relations
this.articlesService
.get(undefined, {
populate: '*',
})
.subscribe((response) => console.log(response.data));
// Specific fields
this.articlesService
.get(undefined, {
populate: ['author', 'category'],
})
.subscribe((response) => console.log(response.data));
// Deep population
this.articlesService
.get(undefined, {
populate: {
author: { fields: ['name', 'email'] },
category: { populate: ['parent'] },
},
})
.subscribe((response) => console.log(response.data));this.articlesService
.get(undefined, {
pagination: { page: 1, pageSize: 10, withCount: true },
})
.subscribe((response) => {
console.log(response.data);
console.log(response.meta.pagination);
});this.articlesService
.get(undefined, {
fields: ['title', 'publishedAt'],
})
.subscribe((response) => console.log(response.data));// Specific locale
this.articlesService
.get(undefined, {
locale: 'en',
})
.subscribe((response) => console.log(response.data));
// Multiple locales
this.articlesService
.get(undefined, {
locale: ['en', 'pl'],
})
.subscribe((response) => console.log(response.data));import { AuthService } from 'angular-strapi-client';
constructor(private authService: AuthService) {}
// Set authentication token (will be used for all requests)
this.authService.setAuthToken('your-jwt-token');
// Get current token
const token = this.authService.getAuthToken();
// Clear authentication token
this.authService.clearAuthToken();get(id?, params?, options?)- Fetch entries or single entrysave(id, data, options?, method?)- Create (id=null) or update entrydelete(id, options?)- Delete entry
setAuthToken(token: string)- Set authentication token for all requestsgetAuthToken()- Get current authentication tokenclearAuthToken()- Remove authentication token
interface StrapiResponse<T> {
data: T[]; // Array of entries or single entry
meta?: {
pagination?: {
page: number;
pageSize: number;
pageCount: number;
total: number;
};
};
}interface StrapiEntry {
id: number; // Numeric ID (legacy)
documentId: string; // Document ID (Strapi v5+)
createdAt: string;
updatedAt: string;
publishedAt: string;
active?: boolean;
}If you encounter CORS errors, ensure your Strapi backend is configured to accept requests from your Angular app origin.
Check that your JWT token is valid and properly set using AuthService.setAuthToken().
Verify the API path in your service matches your Strapi content type (e.g., /api/articles not /articles).
- Angular 19.2.0+
- Strapi v5+