-
Notifications
You must be signed in to change notification settings - Fork 1
backend restapi Overview
GitHub Action edited this page May 21, 2026
·
1 revision
A scalable and flexible backend adapter for integrating Quatrain applications with remote REST APIs.
This package provides RestBackendAdapter, which implements the AbstractBackendAdapter interface. It translates Quatrain's standard CRUD methods (create, read, update, delete, find) into RESTful HTTP requests using the @quatrain/api-client.
-
Configurable Endpoints: Map models directly to specific endpoints via
endpointMap. -
Method Restrictions: Explicitly define
allowedMethodsto prevent unsupported CRUD actions. -
Dynamic Querying: Customize how Quatrain
FiltersandSortAndLimitmap to query strings via thequerySerializer. - Authentication: Native support for Basic, Bearer, and generic OAuth via the API Client.
import { RestBackendAdapter } from '@quatrain/backend-restapi'
import { BearerAuthProvider } from '@quatrain/api-client'
const restAdapter = new RestBackendAdapter({
baseUrl: 'https://api.example.com/v1',
endpointMap: {
'User': '/users',
'Post': '/posts'
},
allowedMethods: ['read', 'find', 'create'], // Disallow update/delete
authProvider: new BearerAuthProvider('my-token'),
querySerializer: (filters, pagination) => {
// Custom filter mapping...
return { offset: pagination?.limits.offset, limit: pagination?.limits.batch }
}
})
// Use the adapter in your Backend initialization
Backend.init(restAdapter)For complex integrations, you can extend the adapter:
class CustomRestAdapter extends RestBackendAdapter {
protected buildUrl(collectionName: string, uid?: string): string {
// Custom URL logic
return super.buildUrl(collectionName, uid)
}
}See the @quatrain/backend-restapi-recipes package for community-maintained query serializers for famous APIs (OpenWeatherMap, CoinGecko, etc.).
- Multi-Format Parsing: Evolve
ApiClientto respect theresponseTypeparameter (avoiding forced.json()) to allow ingestingCSVorXMLpayloads. - Custom Response Parsers: Introduce a
responseParser?: (rawResponse: any) => Record<string, any>[]inRestAdapterOptionsto parse exotic formats into Quatrain-compatible objects. - Hypertext API Navigation: Support HTML-based APIs by utilizing
@quatrain/aiwithin theresponseParserto extract JSON from unstructured web pages.