o24ui-api-client
v4.0.1
Published
HTTP client and API services for EMI Portal applications
Maintainers
Readme
@emi-portal/api-client
HTTP client and API service layer for EMI Portal applications.
Features
- HTTP client with authentication support
- Automatic token injection
- Error interceptors (401, 422, 500, etc.)
- Workflow-based request helpers
- TypeScript support with full type safety
- Timeout and retry handling
Installation
{
"dependencies": {
"@emi-portal/api-client": "*"
}
}Usage
HTTP Client
import { createHttpClient } from '@emi-portal/api-client';
const client = createHttpClient({
baseURL: process.env.NEXT_PUBLIC_API_URL!,
token: session?.user?.token,
});
// Make requests
const response = await client.get('/api/users');
const data = await client.post('/api/login', { username, password });Workflow API Helpers
import { createDefaultBody, apiPost } from '@emi-portal/api-client';
const body = createDefaultBody('GET_USER_INFO', { userId: '123' });
const result = await apiPost(client, '/api/workflow', body, token);Error Handling
import { EntityError, isEntityError, handleApiError } from '@emi-portal/api-client';
try {
await client.post('/api/submit', data);
} catch (error) {
if (isEntityError(error)) {
// Handle validation errors
console.log(error.errors);
} else {
handleApiError(error);
}
}Architecture
This package mirrors the pattern from src/servers/lib/:
- HTTP wrapper with interceptors
- Standardized error handling
- Auth token management
- Workflow request structure
