|
| 1 | +--- |
| 2 | +title: Rest Server |
| 3 | +description: Rest Server protocol schemas |
| 4 | +--- |
| 5 | + |
| 6 | +# Rest Server |
| 7 | + |
| 8 | +<Callout type="info"> |
| 9 | +**Source:** `packages/spec/src/api/rest-server.zod.ts` |
| 10 | +</Callout> |
| 11 | + |
| 12 | +## TypeScript Usage |
| 13 | + |
| 14 | +```typescript |
| 15 | +import { BatchEndpointsConfigSchema, CrudEndpointPatternSchema, CrudEndpointsConfigSchema, CrudOperationSchema, EndpointRegistrySchema, GeneratedEndpointSchema, MetadataEndpointsConfigSchema, RestApiConfigSchema, RestServerConfigSchema, RouteGenerationConfigSchema } from '@objectstack/spec/api'; |
| 16 | +import type { BatchEndpointsConfig, CrudEndpointPattern, CrudEndpointsConfig, CrudOperation, EndpointRegistry, GeneratedEndpoint, MetadataEndpointsConfig, RestApiConfig, RestServerConfig, RouteGenerationConfig } from '@objectstack/spec/api'; |
| 17 | + |
| 18 | +// Validate data |
| 19 | +const result = BatchEndpointsConfigSchema.parse(data); |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## BatchEndpointsConfig |
| 25 | + |
| 26 | +### Properties |
| 27 | + |
| 28 | +| Property | Type | Required | Description | |
| 29 | +| :--- | :--- | :--- | :--- | |
| 30 | +| **maxBatchSize** | `integer` | optional | Maximum records per batch operation | |
| 31 | +| **enableBatchEndpoint** | `boolean` | optional | Enable POST /data/:object/batch endpoint | |
| 32 | +| **operations** | `object` | optional | Enable/disable specific batch operations | |
| 33 | +| **defaultAtomic** | `boolean` | optional | Default atomic/transaction mode for batch operations | |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## CrudEndpointPattern |
| 38 | + |
| 39 | +### Properties |
| 40 | + |
| 41 | +| Property | Type | Required | Description | |
| 42 | +| :--- | :--- | :--- | :--- | |
| 43 | +| **method** | `Enum<'GET' \| 'POST' \| 'PUT' \| 'DELETE' \| 'PATCH' \| 'HEAD' \| 'OPTIONS'>` | ✅ | HTTP method | |
| 44 | +| **path** | `string` | ✅ | URL path pattern | |
| 45 | +| **summary** | `string` | optional | Operation summary | |
| 46 | +| **description** | `string` | optional | Operation description | |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## CrudEndpointsConfig |
| 51 | + |
| 52 | +### Properties |
| 53 | + |
| 54 | +| Property | Type | Required | Description | |
| 55 | +| :--- | :--- | :--- | :--- | |
| 56 | +| **operations** | `object` | optional | Enable/disable operations | |
| 57 | +| **patterns** | `Record<string, object>` | optional | Custom URL patterns for operations | |
| 58 | +| **dataPrefix** | `string` | optional | URL prefix for data endpoints | |
| 59 | +| **objectParamStyle** | `Enum<'path' \| 'query'>` | optional | How object name is passed (path param or query param) | |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## CrudOperation |
| 64 | + |
| 65 | +### Allowed Values |
| 66 | + |
| 67 | +* `create` |
| 68 | +* `read` |
| 69 | +* `update` |
| 70 | +* `delete` |
| 71 | +* `list` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## EndpointRegistry |
| 76 | + |
| 77 | +### Properties |
| 78 | + |
| 79 | +| Property | Type | Required | Description | |
| 80 | +| :--- | :--- | :--- | :--- | |
| 81 | +| **endpoints** | `object[]` | ✅ | All generated endpoints | |
| 82 | +| **total** | `integer` | ✅ | Total number of endpoints | |
| 83 | +| **byObject** | `Record<string, object[]>` | optional | Endpoints grouped by object | |
| 84 | +| **byOperation** | `Record<string, object[]>` | optional | Endpoints grouped by operation | |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## GeneratedEndpoint |
| 89 | + |
| 90 | +### Properties |
| 91 | + |
| 92 | +| Property | Type | Required | Description | |
| 93 | +| :--- | :--- | :--- | :--- | |
| 94 | +| **id** | `string` | ✅ | Unique endpoint identifier | |
| 95 | +| **method** | `Enum<'GET' \| 'POST' \| 'PUT' \| 'DELETE' \| 'PATCH' \| 'HEAD' \| 'OPTIONS'>` | ✅ | HTTP method | |
| 96 | +| **path** | `string` | ✅ | Full URL path | |
| 97 | +| **object** | `string` | ✅ | Object name (snake_case) | |
| 98 | +| **operation** | `Enum<'create' \| 'read' \| 'update' \| 'delete' \| 'list'> \| string` | ✅ | Operation type | |
| 99 | +| **handler** | `string` | ✅ | Handler function identifier | |
| 100 | +| **metadata** | `object` | optional | | |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## MetadataEndpointsConfig |
| 105 | + |
| 106 | +### Properties |
| 107 | + |
| 108 | +| Property | Type | Required | Description | |
| 109 | +| :--- | :--- | :--- | :--- | |
| 110 | +| **prefix** | `string` | optional | URL prefix for metadata endpoints | |
| 111 | +| **enableCache** | `boolean` | optional | Enable HTTP cache headers (ETag, Last-Modified) | |
| 112 | +| **cacheTtl** | `integer` | optional | Cache TTL in seconds | |
| 113 | +| **endpoints** | `object` | optional | Enable/disable specific endpoints | |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## RestApiConfig |
| 118 | + |
| 119 | +### Properties |
| 120 | + |
| 121 | +| Property | Type | Required | Description | |
| 122 | +| :--- | :--- | :--- | :--- | |
| 123 | +| **version** | `string` | optional | API version (e.g., v1, v2, 2024-01) | |
| 124 | +| **basePath** | `string` | optional | Base URL path for API | |
| 125 | +| **apiPath** | `string` | optional | Full API path (defaults to `{basePath}`/`{version}`) | |
| 126 | +| **enableCrud** | `boolean` | optional | Enable automatic CRUD endpoint generation | |
| 127 | +| **enableMetadata** | `boolean` | optional | Enable metadata API endpoints | |
| 128 | +| **enableBatch** | `boolean` | optional | Enable batch operation endpoints | |
| 129 | +| **enableDiscovery** | `boolean` | optional | Enable API discovery endpoint | |
| 130 | +| **documentation** | `object` | optional | OpenAPI/Swagger documentation config | |
| 131 | +| **responseFormat** | `object` | optional | Response format options | |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## RestServerConfig |
| 136 | + |
| 137 | +### Properties |
| 138 | + |
| 139 | +| Property | Type | Required | Description | |
| 140 | +| :--- | :--- | :--- | :--- | |
| 141 | +| **api** | `object` | optional | REST API configuration | |
| 142 | +| **crud** | `object` | optional | CRUD endpoints configuration | |
| 143 | +| **metadata** | `object` | optional | Metadata endpoints configuration | |
| 144 | +| **batch** | `object` | optional | Batch endpoints configuration | |
| 145 | +| **routes** | `object` | optional | Route generation configuration | |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +## RouteGenerationConfig |
| 150 | + |
| 151 | +### Properties |
| 152 | + |
| 153 | +| Property | Type | Required | Description | |
| 154 | +| :--- | :--- | :--- | :--- | |
| 155 | +| **includeObjects** | `string[]` | optional | Specific objects to generate routes for (empty = all) | |
| 156 | +| **excludeObjects** | `string[]` | optional | Objects to exclude from route generation | |
| 157 | +| **nameTransform** | `Enum<'none' \| 'plural' \| 'kebab-case' \| 'camelCase'>` | optional | Transform object names in URLs | |
| 158 | +| **overrides** | `Record<string, object>` | optional | Per-object route customization | |
| 159 | + |
0 commit comments