-
Notifications
You must be signed in to change notification settings - Fork 1
api server express HowTo
GitHub Action edited this page May 21, 2026
·
1 revision
The @quatrain/api-server-express package allows you to expose your Quatrain models over HTTP instantly using an ExpressAdapter.
Initialize the ExpressAdapter and pass any standard Express middlewares (like CORS or JSON parsers).
import { ExpressAdapter } from '@quatrain/api-server-express';
const server = new ExpressAdapter();You can bind full CRUD endpoints to a specific model. Note that endpoints are imported from @quatrain/api-server!
import { CrudEndpoint, ListEndpoint } from '@quatrain/api-server';
import { ExpressAdapter } from '@quatrain/api-server-express';
import { StudioModel } from '@quatrain/studio';
import { Api } from '@quatrain/api';
const server = new ExpressAdapter();
// Create a GET /api/models endpoint to list models
server.addEndpoint(
'/api/models',
ListEndpoint(StudioModel)
);
// Create full POST, GET, PUT, DELETE for individual models
server.addEndpoint(
'/api/models',
CrudEndpoint(StudioModel),
{ methods: ['CREATE', 'READ', 'UPDATE', 'DELETE'] }
);const PORT = 4000;
server.start(PORT, () => {
Api.info(`Server listening on port ${PORT}`);
});