@objectstack/rest 4.0.4 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,43 +1,48 @@
1
1
  # @objectstack/rest
2
2
 
3
- ObjectStack REST API Server automatic REST endpoint generation from protocol metadata. Turns your ObjectStack schema definitions into fully functional CRUD endpoints with zero boilerplate.
3
+ > Auto-generated REST API layer for ObjectStack turns protocol metadata into CRUD, batch, metadata, and discovery endpoints with zero boilerplate.
4
4
 
5
- ## Features
5
+ [![npm](https://img.shields.io/npm/v/@objectstack/rest.svg)](https://www.npmjs.com/package/@objectstack/rest)
6
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
7
 
7
- - **Auto-Generated Endpoints**: CRUD routes (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`) from object schemas.
8
- - **Batch Operations**: `/createMany`, `/updateMany`, `/deleteMany`, `/batch` endpoints.
9
- - **Metadata API**: `/meta`, `/meta/{type}`, `/meta/{type}/{name}` for runtime introspection.
10
- - **Discovery Endpoint**: `/api/v1` for API self-documentation.
11
- - **Route Manager**: Centralized route registration, grouping, and middleware chain.
12
- - **HTTP Caching**: ETag and Last-Modified header support.
13
- - **Configurable Paths**: Plural, kebab-case, and camelCase path transformations.
8
+ ## Overview
14
9
 
15
- ## Usage
10
+ `@objectstack/rest` is registered as a kernel plugin and emits HTTP routes for every object defined in the protocol metadata. Framework adapters (`@objectstack/express`, `hono`, `fastify`, `nextjs`, `nuxt`, `nestjs`, `sveltekit`) invoke these routes through `HttpDispatcher` from `@objectstack/runtime`.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @objectstack/rest
16
+ ```
17
+
18
+ ## Quick Start
16
19
 
17
20
  ```typescript
21
+ import { ObjectKernel } from '@objectstack/core';
18
22
  import { createRestApiPlugin } from '@objectstack/rest';
19
23
 
20
- const restPlugin = createRestApiPlugin({
24
+ const kernel = new ObjectKernel();
25
+
26
+ kernel.use(createRestApiPlugin({
21
27
  api: {
22
28
  version: 'v1',
23
29
  basePath: '/api',
24
30
  },
25
- });
31
+ }));
26
32
 
27
- // Register with ObjectKernel
28
- kernel.use(restPlugin);
33
+ await kernel.bootstrap();
29
34
  ```
30
35
 
31
- ### Standalone RestServer
36
+ ### Standalone `RestServer`
32
37
 
33
38
  ```typescript
34
39
  import { RestServer } from '@objectstack/rest';
35
40
 
36
41
  const server = new RestServer(protocol, config);
37
- server.registerRoutes(httpServer);
42
+ server.registerRoutes(dispatcher);
38
43
  ```
39
44
 
40
- ### Route Manager
45
+ ### Custom routes via `RouteManager`
41
46
 
42
47
  ```typescript
43
48
  import { RouteManager } from '@objectstack/rest';
@@ -46,6 +51,78 @@ const routes = new RouteManager();
46
51
  routes.register({ method: 'GET', path: '/custom', handler });
47
52
  ```
48
53
 
54
+ ## Generated endpoints
55
+
56
+ For every object `Project` defined in metadata, the plugin exposes:
57
+
58
+ | Method | Path | Purpose |
59
+ |:---|:---|:---|
60
+ | `GET` | `/api/v1/projects` | List with `filter`, `sort`, `top`, `skip`, `select`, `groupBy`, `aggregations`. |
61
+ | `GET` | `/api/v1/projects/:id` | Single record (with ETag / Last-Modified). |
62
+ | `POST` | `/api/v1/projects` | Create. |
63
+ | `PATCH` | `/api/v1/projects/:id` | Partial update. |
64
+ | `PUT` | `/api/v1/projects/:id` | Full replacement. |
65
+ | `DELETE` | `/api/v1/projects/:id` | Delete. |
66
+ | `POST` | `/api/v1/projects/createMany` | Batch create. |
67
+ | `POST` | `/api/v1/projects/updateMany` | Batch update. |
68
+ | `POST` | `/api/v1/projects/deleteMany` | Batch delete. |
69
+ | `POST` | `/api/v1/projects/batch` | Mixed batch. |
70
+
71
+ Plus metadata and discovery routes:
72
+
73
+ | Path | Description |
74
+ |:---|:---|
75
+ | `/api/v1/meta` | All metadata types. |
76
+ | `/api/v1/meta/:type` | Objects, views, apps, flows, agents, tools, translations. |
77
+ | `/api/v1/meta/:type/:name` | Single metadata resource. |
78
+ | `/api/v1` and `/.well-known/objectstack` | Discovery / service manifest. |
79
+
80
+ ## Key Exports
81
+
82
+ | Export | Kind | Description |
83
+ |:---|:---|:---|
84
+ | `createRestApiPlugin(config)` | function | Kernel plugin factory. |
85
+ | `RestApiPluginConfig` | type | `{ api: { version, basePath }, ... }`. |
86
+ | `RestServer` | class | Direct instantiation for adapters that need it. |
87
+ | `RouteManager`, `RouteGroupBuilder` | classes | Register and group custom routes. |
88
+ | `RouteEntry` | type | Route definition shape. |
89
+
90
+ ## Configuration
91
+
92
+ | Option | Type | Default | Notes |
93
+ |:---|:---|:---|:---|
94
+ | `api.version` | `string` | `'v1'` | Embedded in the route prefix. |
95
+ | `api.basePath` | `string` | `'/api'` | Root path for the API. |
96
+ | `paths.pathTransform` | `'plural' \| 'kebab' \| 'camel'` | `'plural'` | Object → URL segment transform. |
97
+ | `caching.etag` | `boolean` | `true` | Emits `ETag` header. |
98
+ | `caching.lastModified` | `boolean` | `true` | Emits `Last-Modified`. |
99
+
100
+ ## HTTP semantics
101
+
102
+ - JSON envelope: `{ success, data, error?, meta? }`.
103
+ - Validation errors: HTTP 400 with Zod issue list.
104
+ - Auth/permission failures: HTTP 401/403 emitted by `@objectstack/plugin-auth` and `@objectstack/plugin-security`.
105
+ - `If-None-Match` / `If-Modified-Since` honored for GET.
106
+
107
+ ## When to use
108
+
109
+ - ✅ Every runtime that exposes ObjectStack data over HTTP.
110
+
111
+ ## When not to use
112
+
113
+ - ❌ RPC-only or GraphQL-only deployments — use a custom `@objectstack/runtime` consumer.
114
+
115
+ ## Related Packages
116
+
117
+ - [`@objectstack/runtime`](../runtime) — `HttpDispatcher` that invokes routes.
118
+ - Framework adapters under [`packages/adapters/*`](../adapters).
119
+
120
+ ## Links
121
+
122
+ - 📖 Docs: <https://objectstack.ai/docs>
123
+ - 📚 API Reference: <https://objectstack.ai/docs/references/api>
124
+ - 🤖 Skill: [`skills/objectstack-api/SKILL.md`](../../skills/objectstack-api/SKILL.md)
125
+
49
126
  ## License
50
127
 
51
128
  Apache-2.0 © ObjectStack