@@ -26,23 +26,30 @@ By default, ObjectQL uses these API paths:
2626
2727### Basic Usage
2828
29- Configure custom routes when creating handlers :
29+ Configure custom routes when creating the Kernel with protocol plugins :
3030
3131``` typescript
32- import { createNodeHandler , createRESTHandler , createMetadataHandler } from ' @objectql/server' ;
33-
34- // Define custom routes
35- const customRoutes = {
36- rpc: ' /v1/rpc' ,
37- data: ' /v1/resources' ,
38- metadata: ' /v1/schema' ,
39- files: ' /v1/storage'
40- };
41-
42- // Create handlers with custom routes
43- const nodeHandler = createNodeHandler (app , { routes: customRoutes });
44- const restHandler = createRESTHandler (app , { routes: customRoutes });
45- const metadataHandler = createMetadataHandler (app , { routes: customRoutes });
32+ import { ObjectStackKernel } from ' @objectstack/runtime' ;
33+ import { HonoServerPlugin } from ' @objectstack/plugin-hono-server' ;
34+ import { JSONRPCPlugin } from ' @objectql/protocol-json-rpc' ;
35+
36+ // Define custom routes via plugin configuration
37+ const kernel = new ObjectStackKernel ([
38+ appConfig ,
39+ myDriver ,
40+ new ObjectQLPlugin (),
41+ new JSONRPCPlugin ({ basePath: ' /v1/rpc' }),
42+ new HonoServerPlugin ({
43+ port: 3000 ,
44+ routes: {
45+ data: ' /v1/resources' ,
46+ metadata: ' /v1/schema' ,
47+ files: ' /v1/storage'
48+ }
49+ })
50+ ]);
51+
52+ await kernel .start ();
4653```
4754
4855### Route Configuration Interface
@@ -78,62 +85,55 @@ interface ApiRouteConfig {
7885## Complete Example
7986
8087``` typescript
81- import express from ' express' ;
82- import { ObjectQL } from ' @objectql/core' ;
88+ import { ObjectStackKernel } from ' @objectstack/runtime' ;
89+ import { HonoServerPlugin } from ' @objectstack/plugin-hono-server' ;
90+ import { ObjectQLPlugin } from ' @objectql/core' ;
8391import { SqlDriver } from ' @objectql/driver-sql' ;
84- import { createNodeHandler , createRESTHandler , createMetadataHandler } from ' @objectql/server ' ;
92+ import { JSONRPCPlugin } from ' @objectql/protocol-json-rpc ' ;
8593
8694async function main() {
87- // 1. Initialize ObjectQL
88- const app = new ObjectQL ({
89- datasources: {
90- default: new SqlDriver ({
91- client: ' sqlite3' ,
92- connection: { filename: ' :memory:' },
93- useNullAsDefault: true
94- })
95- }
96- });
97-
98- // Register your objects
99- app .registerObject ({
100- name: ' user' ,
101- label: ' User' ,
102- fields: {
103- name: { type: ' text' , label: ' Name' },
104- email: { type: ' email' , label: ' Email' }
95+ // 1. Define app configuration
96+ const appConfig = {
97+ name: ' my-app' ,
98+ objects: {
99+ user: {
100+ name: ' user' ,
101+ label: ' User' ,
102+ fields: {
103+ name: { type: ' text' , label: ' Name' },
104+ email: { type: ' email' , label: ' Email' }
105+ }
106+ }
105107 }
106- });
107-
108- await app .init ();
109-
110- // 2. Define custom API routes
111- const customRoutes = {
112- rpc: ' /v1/rpc' ,
113- data: ' /v1/resources' ,
114- metadata: ' /v1/schema' ,
115- files: ' /v1/storage'
116108 };
117109
118- // 3. Create handlers with custom routes
119- const nodeHandler = createNodeHandler (app , { routes: customRoutes });
120- const restHandler = createRESTHandler (app , { routes: customRoutes });
121- const metadataHandler = createMetadataHandler (app , { routes: customRoutes });
122-
123- // 4. Setup Express with custom paths
124- const server = express ();
110+ // 2. Create Kernel with custom route configuration
111+ const kernel = new ObjectStackKernel ([
112+ appConfig ,
113+ new SqlDriver ({
114+ client: ' sqlite3' ,
115+ connection: { filename: ' :memory:' },
116+ useNullAsDefault: true
117+ }),
118+ new ObjectQLPlugin (),
119+ new JSONRPCPlugin ({ basePath: ' /v1/rpc' }),
120+ new HonoServerPlugin ({
121+ port: 3000 ,
122+ routes: {
123+ data: ' /v1/resources' ,
124+ metadata: ' /v1/schema' ,
125+ files: ' /v1/storage'
126+ }
127+ })
128+ ]);
125129
126- server .all (' /v1/rpc*' , nodeHandler );
127- server .all (' /v1/resources/*' , restHandler );
128- server .all (' /v1/schema*' , metadataHandler );
130+ await kernel .start ();
129131
130- server .listen (3000 , () => {
131- console .log (' 🚀 Server running with custom routes' );
132- console .log (' JSON-RPC: http://localhost:3000/v1/rpc' );
133- console .log (' REST API: http://localhost:3000/v1/resources' );
134- console .log (' Metadata: http://localhost:3000/v1/schema' );
135- console .log (' Files: http://localhost:3000/v1/storage' );
136- });
132+ console .log (' 🚀 Server running with custom routes' );
133+ console .log (' JSON-RPC: http://localhost:3000/v1/rpc' );
134+ console .log (' REST API: http://localhost:3000/v1/resources' );
135+ console .log (' Metadata: http://localhost:3000/v1/schema' );
136+ console .log (' Files: http://localhost:3000/v1/storage' );
137137}
138138
139139main ().catch (console .error );
0 commit comments