Data Access
Overview
Understand the Monospace API structure, endpoints, and response format.
Access the API
Every Monospace project exposes a REST API for reading and writing data. The base URL follows this pattern:
https://{your-instance}/api/{project}/items/{collection}
Fetch all articles from the blog project:
import { createClient } from './generated/monospace';
const client = createClient({
url: 'https://example.monospace.io',
project: 'blog',
apiKey: 'YOUR_API_KEY',
});
const articles = await client.Articles.readMany({
fields: ['*'],
});
curl "https://example.monospace.io/api/blog/items/articles?fields=*" \
-H "Authorization: Bearer YOUR_API_KEY"
const response = await fetch('https://example.monospace.io/api/blog/items/articles?fields=*', {
headers: {
Authorization: 'Bearer YOUR_API_KEY',
},
});
const { data } = await response.json();
Understand the URL Structure
Each segment of the URL targets a specific resource.
| Segment | Example | Description |
|---|---|---|
| Instance URL | https://example.monospace.io | Your Monospace deployment |
| API path | /api | Fixed prefix for all API requests |
| Project slug | /blog | Identifies which project to query |
| Items path | /items | Fixed prefix for collection data |
| Collection | /articles | The collection you are accessing |
| Item ID | /7 | Optional — targets a single item |
The table below maps each CRUD operation to its HTTP method and URL pattern.
| Operation | Method | URL Pattern | Description |
|---|---|---|---|
| List items | GET | /api/{project}/items/{collection} | Retrieve all items in a collection |
| Get single item | GET | /api/{project}/items/{collection}/{id} | Retrieve one item by its primary key |
| Create items | POST | /api/{project}/items/{collection} | Create one or more items |
| Update single item | PATCH | /api/{project}/items/{collection}/{id} | Update an existing item by ID |
| Update many items | PATCH | /api/{project}/items/{collection} | Update items matching a filter |
| Delete single item | DELETE | /api/{project}/items/{collection}/{id} | Remove an item by ID |
| Delete many items | DELETE | /api/{project}/items/{collection} | Remove items matching a filter |
Read the Response Format
All responses are wrapped in a { data } envelope. List endpoints return an array inside data:
response.json
{
"data": [
{ "id": 1, "title": "Getting Started with Monospace", "author": "alice" },
{ "id": 2, "title": "Data Modeling Best Practices", "author": "bob" }
]
}
Single-item endpoints return an object inside data:
response.json
{
"data": {
"id": 1,
"title": "Getting Started with Monospace",
"author": "alice"
}
}
The SDK unwraps the
{ data } envelope automatically. See Client Setup for details.The SDK provides typed methods for every REST endpoint documented here. See the Client SDK Reference for method signatures, type inference, and setup.