|
| 1 | +# @objectql/plugin-server |
| 2 | + |
| 3 | +HTTP server plugin for ObjectQL. Provides Express, Hono, and custom HTTP server support with JSON-RPC, REST, GraphQL, and Metadata APIs. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @objectql/plugin-server |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +### As a Plugin |
| 14 | + |
| 15 | +```typescript |
| 16 | +import { ObjectQL } from '@objectql/core'; |
| 17 | +import { ServerPlugin } from '@objectql/plugin-server'; |
| 18 | + |
| 19 | +const app = new ObjectQL({ |
| 20 | + datasources: { /* ... */ }, |
| 21 | + plugins: [ |
| 22 | + new ServerPlugin({ |
| 23 | + port: 3000, |
| 24 | + autoStart: true, |
| 25 | + enableREST: true, |
| 26 | + enableRPC: true, |
| 27 | + enableMetadata: true |
| 28 | + }) |
| 29 | + ] |
| 30 | +}); |
| 31 | + |
| 32 | +await app.init(); |
| 33 | +``` |
| 34 | + |
| 35 | +### With Hono Framework |
| 36 | + |
| 37 | +```typescript |
| 38 | +import { Hono } from 'hono'; |
| 39 | +import { ObjectQL } from '@objectql/core'; |
| 40 | +import { createHonoAdapter } from '@objectql/plugin-server/adapters/hono'; |
| 41 | + |
| 42 | +const app = new ObjectQL({ /* ... */ }); |
| 43 | +await app.init(); |
| 44 | + |
| 45 | +const server = new Hono(); |
| 46 | +const objectqlHandler = createHonoAdapter(app); |
| 47 | + |
| 48 | +server.all('/api/*', objectqlHandler); |
| 49 | + |
| 50 | +export default server; |
| 51 | +``` |
| 52 | + |
| 53 | +### With Express |
| 54 | + |
| 55 | +```typescript |
| 56 | +import express from 'express'; |
| 57 | +import { ObjectQL } from '@objectql/core'; |
| 58 | +import { createNodeHandler } from '@objectql/plugin-server'; |
| 59 | + |
| 60 | +const app = new ObjectQL({ /* ... */ }); |
| 61 | +await app.init(); |
| 62 | + |
| 63 | +const server = express(); |
| 64 | +const objectqlHandler = createNodeHandler(app); |
| 65 | + |
| 66 | +server.all('/api/*', objectqlHandler); |
| 67 | + |
| 68 | +server.listen(3000); |
| 69 | +``` |
| 70 | + |
| 71 | +## Features |
| 72 | + |
| 73 | +### JSON-RPC API |
| 74 | +- Protocol-first approach |
| 75 | +- Supports all ObjectQL operations |
| 76 | +- Type-safe requests and responses |
| 77 | + |
| 78 | +### REST API |
| 79 | +- Standard HTTP methods (GET, POST, PUT, DELETE) |
| 80 | +- RESTful resource endpoints |
| 81 | +- Query parameter support |
| 82 | + |
| 83 | +### GraphQL API |
| 84 | +- Auto-generated schema from ObjectQL metadata |
| 85 | +- Support for queries and mutations |
| 86 | +- Introspection support |
| 87 | + |
| 88 | +### Metadata API |
| 89 | +- Explore object schemas |
| 90 | +- Discover available operations |
| 91 | +- Runtime schema inspection |
| 92 | + |
| 93 | +### File Upload/Download |
| 94 | +- Single and batch file uploads |
| 95 | +- Secure file storage |
| 96 | +- File download support |
| 97 | + |
| 98 | +## Configuration Options |
| 99 | + |
| 100 | +```typescript |
| 101 | +interface ServerPluginOptions { |
| 102 | + port?: number; // Default: 3000 |
| 103 | + host?: string; // Default: 'localhost' |
| 104 | + routes?: ApiRouteConfig; // Custom route configuration |
| 105 | + fileStorage?: IFileStorage; // Custom file storage |
| 106 | + enableGraphQL?: boolean; // Default: false |
| 107 | + enableREST?: boolean; // Default: true |
| 108 | + enableMetadata?: boolean; // Default: true |
| 109 | + enableRPC?: boolean; // Default: true |
| 110 | + autoStart?: boolean; // Default: false |
| 111 | + middleware?: Function[]; // Custom middleware |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +## API Routes |
| 116 | + |
| 117 | +Default routes (customizable): |
| 118 | +- JSON-RPC: `/api/objectql` |
| 119 | +- REST: `/api/data` |
| 120 | +- GraphQL: `/api/graphql` |
| 121 | +- Metadata: `/api/metadata` |
| 122 | +- Files: `/api/files` |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +MIT |
0 commit comments