-
Notifications
You must be signed in to change notification settings - Fork 1
api client HowTo
GitHub Action edited this page May 21, 2026
·
1 revision
The ApiClient is a singleton pattern class designed to unify HTTP requests across the application.
You must provide a base URL when initializing the instance:
import { ApiClient } from '@quatrain/api-client';
const API_BASE_URL = 'http://localhost:4000/api';
const apiClient = ApiClient.instance(API_BASE_URL);The client provides helper methods for standard REST operations. All methods return a standard ApiPayload wrapper containing data and meta.
// Fetch a list (with query parameters)
const response = await apiClient.get('models', { offset: 0, batch: 50 });
console.log(response.data);
// Fetch a single item
const model = await apiClient.get(`models/${id}`);// Create a new resource
const newModel = await apiClient.post('models', {
name: 'User',
collectionName: 'users'
});// Update an existing resource
await apiClient.put(`models/${id}`, {
isPersisted: true
});// Delete a resource
await apiClient.delete(`models/${id}`);If your API requires authentication, you can pass an AuthProvider instance to the ApiClient.
import { AuthProvider } from '@quatrain/api-client';
class MyAuthProvider extends AuthProvider {
getToken() {
return localStorage.getItem('token');
}
}
apiClient.authProvider = new MyAuthProvider();
// All subsequent requests will include the 'Authorization: Bearer <token>' header.