Server Integration
Server Integration
ObjectQL is designed to be framework-agnostic. While it can be used directly as a library, we provide a standard @objectql/server package to expose your application via HTTP.
The @objectql/server Package
This package provides a standardized way to handle HTTP requests, similar to libraries like better-auth. It receives a standard JSON request body and routes it to the correct internal ObjectQL operation (find, create, action, etc.).
Installation
Supported Frameworks
1. Node.js (Raw HTTP)
You can mount the handler directly on a native Node.js http.Server.
2. Express
Mount ObjectQL on any route path.
3. Next.js (Pages Router)
The Protocol
The server exposes a single endpoint that accepts POST requests with a JSON body defined by ObjectQLRequest:
📖 OpenAPI Support
@objectql/server automatically generates an OpenAPI 3.0 specification from your registered schema.
This powers the built-in API Docs (available at /docs in CLI mode).
You can access the raw spec by appending /openapi.json to your handler's mount path.
Example URLs:
- CLI Serve:
http://localhost:3000/openapi.json - Express (mounted at /api/objectql):
http://localhost:3000/api/objectql/openapi.json - Next.js (pages/api/objectql.ts):
http://localhost:3000/api/objectql/openapi.json
This JSON file describes your data objects as "Virtual REST" endpoints (GET /user, POST /user, etc.), allowing you to easily import them into Scalar, Swagger UI, Postman, or other API tools for visualization and testing.
Example Usage
Example (cURL):
Dev Server
For rapid prototyping, @objectql/cli provides a built-in dev server.
See CLI Documentation for more details.