|
| 1 | +--- |
| 2 | +title: REST API Protocol |
| 3 | +description: Standard Data API and Metadata API Specification |
| 4 | +--- |
| 5 | + |
| 6 | +# REST API Protocol |
| 7 | + |
| 8 | +ObjectStack follows the "Protocol First" principle, providing a set of standardized RESTful APIs for interaction between the frontend and the ObjectOS kernel. |
| 9 | + |
| 10 | +To solve the problem of hardcoded URL paths, ObjectStack introduces the **Discovery Protocol**, Clients should first request the discovery endpoint to obtain service entry points for the current environment. |
| 11 | + |
| 12 | +## 1. Discovery |
| 13 | + |
| 14 | +When the client starts (e.g., `App.init`), it should first request this endpoint. |
| 15 | + |
| 16 | +- **Endpoint**: `GET /.well-known/objectstack` or `GET /api/v1/discovery` |
| 17 | +- **Response Type**: `DiscoveryResponse` |
| 18 | + |
| 19 | +```json |
| 20 | +{ |
| 21 | + "name": "Acme CRM Production", |
| 22 | + "version": "1.0.0", |
| 23 | + "environment": "production", |
| 24 | + "routes": { |
| 25 | + "data": "/api/v1/data", |
| 26 | + "metadata": "/api/v1/meta", |
| 27 | + "auth": "/api/v1/auth", |
| 28 | + "actions": "/api/v1/actions", |
| 29 | + "storage": "/api/v1/storage", |
| 30 | + "graphql": "/api/v1/graphql" |
| 31 | + }, |
| 32 | + "features": { |
| 33 | + "graphql": true, |
| 34 | + "search": true, |
| 35 | + "files": true |
| 36 | + }, |
| 37 | + "locale": { |
| 38 | + "default": "en-US", |
| 39 | + "supported": ["en-US", "zh-CN"], |
| 40 | + "timezone": "America/Los_Angeles" |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## 2. Standard Data API |
| 46 | + |
| 47 | +Based on the base path returned by `routes.data` (default is `/api/v1/data`). |
| 48 | + |
| 49 | +### Query Objects (Query) |
| 50 | + |
| 51 | +- **Method**: `GET /:objectName` |
| 52 | +- **Params**: |
| 53 | + - `select`: List of fields (comma separated) |
| 54 | + - `filter`: Filter criteria (JSON string, see `filters` in QuerySchema) |
| 55 | + - `sort`: Sorting (e.g. `created_at desc`) |
| 56 | + - `page`: Page number |
| 57 | + - `pageSize`: Items per page |
| 58 | + |
| 59 | +### Get Single Record (Retrieve) |
| 60 | + |
| 61 | +- **Method**: `GET /:objectName/:recordId` |
| 62 | + |
| 63 | +### Create Record (Create) |
| 64 | + |
| 65 | +- **Method**: `POST /:objectName` |
| 66 | +- **Body**: Record data object |
| 67 | + |
| 68 | +### Update Record (Update) |
| 69 | + |
| 70 | +- **Method**: `PATCH /:objectName/:recordId` |
| 71 | +- **Body**: Changed fields |
| 72 | + |
| 73 | +### Delete Record (Delete) |
| 74 | + |
| 75 | +- **Method**: `DELETE /:objectName/:recordId` |
| 76 | + |
| 77 | +## 3. Standard Metadata API |
| 78 | + |
| 79 | +Based on the base path returned by `routes.metadata` (default is `/api/v1/meta`). |
| 80 | + |
| 81 | +### Get All Object Definitions |
| 82 | + |
| 83 | +- **Method**: `GET /objects` |
| 84 | +- **Response**: List of `ObjectSchema` (summary) |
| 85 | + |
| 86 | +### Get Specific Object Definition |
| 87 | + |
| 88 | +- **Method**: `GET /objects/:objectName` |
| 89 | +- **Response**: Full `ObjectSchema` (incl. fields, validation) |
| 90 | + |
| 91 | +### Get App Navigation Menus |
| 92 | + |
| 93 | +- **Method**: `GET /menus` |
| 94 | +- **Response**: `MenuItem[]` |
| 95 | + |
| 96 | +## 4. Custom API Endpoints |
| 97 | + |
| 98 | +Developers can define custom API interfaces via `ApiEndpointSchema`, which are typically mounted under `/api/v1/custom` or a custom path. |
| 99 | + |
| 100 | +See [Custom API Guide](/docs/specifications/server/custom-api). |
0 commit comments