Skip to content

Commit ac8b9c9

Browse files
REST Section Migration (#457)
Adds all 5 pages of the REST reference section: - overview.md: HTTP methods (GET/PUT/POST/PATCH/DELETE), URL structure, ETag caching, OpenAPI endpoint - querying.md: Full URL query syntax — FIQL operators, unions, grouping, select/limit/sort functions, relationships/joins, null queries, type conversion - headers.md: Request/response headers (ETag, If-None-Match, Content-Type, Accept, etc.) - content-types.md: JSON, CBOR, MessagePack, CSV — with encoding recommendations - websockets.md: WebSocket connections, custom connect() handler, MQTT-over-WS, message ordering - server-sent-events.md: SSE connections, one-directional streaming, connect() usage Also adds rest-link-placeholders.md and marks REST section Complete in migration map. Co-authored-by: Claude Sonnet 4.6 <[email protected]>
1 parent 91181d8 commit ac8b9c9

File tree

9 files changed

+870
-7
lines changed

9 files changed

+870
-7
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Link Placeholders for REST Section
2+
3+
## reference_versioned_docs/version-v4/rest/overview.md
4+
5+
- Line (See Also): `[Database / Schema](TODO:reference_versioned_docs/version-v4/database/schema.md 'Schema definition')`
6+
- Context: Intro and See Also section — how to define and export resources
7+
- Target should be: Database / Schema page
8+
- **Status**: PENDING (Database section migration)
9+
10+
## reference_versioned_docs/version-v4/rest/querying.md
11+
12+
- Line (directURLMapping section): `[Database / Schema](TODO:reference_versioned_docs/version-v4/database/schema.md 'Schema and resource configuration')`
13+
- Context: directURLMapping option reference
14+
- Target should be: Database / Schema page
15+
- **Status**: PENDING (Database section migration)
16+
17+
- Line (See Also): `[Database / Schema](TODO:reference_versioned_docs/version-v4/database/schema.md 'Schema definition')`
18+
- Context: See Also section
19+
- Target should be: Database / Schema page
20+
- **Status**: PENDING (Database section migration)
21+
22+
## reference_versioned_docs/version-v4/rest/websockets.md
23+
24+
- Line (Custom connect() Handler): `[Resource API](TODO:reference_versioned_docs/version-v4/resources/resource-api.md 'Resource API reference')`
25+
- Context: Inline link for more on implementing custom resources
26+
- Target should be: Resources / Resource API page
27+
- **Status**: PENDING (Resources section migration)
28+
29+
- Line (See Also): `[Resources](TODO:reference_versioned_docs/version-v4/resources/overview.md 'Resources overview')`
30+
- Context: Link to custom resource API including `connect()` method
31+
- Target should be: Resources section overview page
32+
- **Status**: PENDING (Resources section migration)
33+
34+
## reference_versioned_docs/version-v4/rest/server-sent-events.md
35+
36+
- Line (See Also): `[Resources](TODO:reference_versioned_docs/version-v4/resources/overview.md 'Resources overview')`
37+
- Context: Link to custom resource API including `connect()` method
38+
- Target should be: Resources section overview page
39+
- **Status**: PENDING (Resources section migration)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: Content Types
3+
---
4+
5+
<!-- Source: versioned_docs/version-4.7/reference/content-types.md (primary) -->
6+
<!-- Source: versioned_docs/version-4.7/developers/rest.md (content negotiation section) -->
7+
8+
# Content Types
9+
10+
Harper supports multiple content types (MIME types) for both HTTP request bodies and response bodies. Harper follows HTTP standards: use the `Content-Type` request header to specify the encoding of the request body, and use the `Accept` header to request a specific response format.
11+
12+
```http
13+
Content-Type: application/cbor
14+
Accept: application/cbor
15+
```
16+
17+
All content types work with any standard Harper operation.
18+
19+
## Supported Formats
20+
21+
### JSON — `application/json`
22+
23+
JSON is the most widely used format, readable and easy to work with. It is well-supported across all HTTP tooling.
24+
25+
**Limitations**: JSON does not natively support all Harper data types — binary data, `Date`, `Map`, and `Set` values require special handling. JSON also produces larger payloads than binary formats.
26+
27+
**When to use**: Web development, debugging, interoperability with third-party clients, or when the standard JSON type set is sufficient. Pairing JSON with compression (`Accept-Encoding: gzip, br`) often yields compact network transfers due to favorable Huffman coding characteristics.
28+
29+
### CBOR — `application/cbor`
30+
31+
CBOR is the recommended format for most production use cases. It is a highly efficient binary format with native support for the full range of Harper data types, including binary data, typed dates, and explicit Maps/Sets.
32+
33+
**Advantages**: Very compact encoding, fast serialization, native streaming support (indefinite-length arrays for optimal time-to-first-byte on query results). Well-standardized with growing ecosystem support.
34+
35+
**When to use**: Production APIs, performance-sensitive applications, or any scenario requiring rich data types.
36+
37+
### MessagePack — `application/x-msgpack`
38+
39+
MessagePack is another efficient binary format similar to CBOR, with broader adoption in some ecosystems. It supports all Harper data types.
40+
41+
**Limitations**: MessagePack does not natively support streaming arrays, so query results are returned as a concatenated sequence of MessagePack objects. Decoders must be prepared to handle a sequence of values rather than a single document.
42+
43+
**When to use**: Systems with existing MessagePack support that don't have CBOR available, or when interoperability with MessagePack clients is required. CBOR is generally preferred when both are available.
44+
45+
### CSV — `text/csv`
46+
47+
Comma-separated values format, suitable for data export and spreadsheet import/export. CSV lacks hierarchical structure and explicit typing.
48+
49+
**When to use**: Ad-hoc data export, spreadsheet workflows, batch data processing. Not recommended for frequent or production API use.
50+
51+
## Content Type via URL Extension
52+
53+
As an alternative to the `Accept` header, responses can be requested in a specific format using file-style URL extensions:
54+
55+
```http
56+
GET /product/some-id.csv
57+
GET /product/.msgpack?category=software
58+
```
59+
60+
Using the `Accept` header is the recommended approach for clean, standard HTTP interactions.
61+
62+
## Custom Content Types
63+
64+
Harper's content type system is extensible. Custom handlers for any serialization format (XML, YAML, proprietary formats, etc.) can be registered in the [`contentTypes`](../resources/global-apis.md) global Map.
65+
66+
## Storing Arbitrary Content Types
67+
68+
When a `PUT` or `POST` is made with a non-standard content type (e.g., `text/calendar`, `image/gif`), Harper stores the content as a record with `contentType` and `data` properties:
69+
70+
```http
71+
PUT /my-resource/33
72+
Content-Type: text/calendar
73+
74+
BEGIN:VCALENDAR
75+
VERSION:2.0
76+
...
77+
```
78+
79+
This stores a record equivalent to:
80+
81+
```json
82+
{ "contentType": "text/calendar", "data": "BEGIN:VCALENDAR\nVERSION:2.0\n..." }
83+
```
84+
85+
Retrieving a record that has `contentType` and `data` properties returns the response with the specified `Content-Type` and body. If the content type is not from the `text` family, the data is treated as binary (a Node.js `Buffer`).
86+
87+
Use `application/octet-stream` for binary data or for uploading to a specific property:
88+
89+
```http
90+
PUT /my-resource/33/image
91+
Content-Type: image/gif
92+
93+
...image data...
94+
```
95+
96+
## See Also
97+
98+
- [REST Overview](./overview.md) — HTTP methods and URL structure
99+
- [Headers](./headers.md) — Content negotiation headers
100+
- [Querying](./querying.md) — URL query syntax
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: REST Headers
3+
---
4+
5+
<!-- Source: versioned_docs/version-4.7/reference/headers.md (primary) -->
6+
<!-- Source: versioned_docs/version-4.7/developers/rest.md (ETag/conditional request headers) -->
7+
8+
# REST Headers
9+
10+
Harper's REST interface uses standard HTTP headers for content negotiation, caching, and performance instrumentation.
11+
12+
## Response Headers
13+
14+
These headers are included in all Harper REST API responses:
15+
16+
| Header | Example Value | Description |
17+
| --------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `server-timing` | `db;dur=7.165` | Duration of the operation in milliseconds. Follows the [Server-Timing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing) standard and can be consumed by network monitoring tools. |
19+
| `content-type` | `application/json` | MIME type of the returned content, negotiated based on the `Accept` request header. |
20+
| `etag` | `"abc123"` | Encoded version/last-modification time of the returned record. Used for conditional requests. |
21+
| `location` | `/MyTable/new-id` | Returned on `POST` responses. Contains the path to the newly created record. |
22+
23+
## Request Headers
24+
25+
### Content-Type
26+
27+
Specifies the format of the request body (for `PUT`, `PATCH`, `POST`):
28+
29+
```http
30+
Content-Type: application/json
31+
Content-Type: application/cbor
32+
Content-Type: application/x-msgpack
33+
Content-Type: text/csv
34+
```
35+
36+
See [Content Types](./content-types.md) for the full list of supported formats.
37+
38+
### Accept
39+
40+
Specifies the preferred response format:
41+
42+
```http
43+
Accept: application/json
44+
Accept: application/cbor
45+
Accept: application/x-msgpack
46+
Accept: text/csv
47+
```
48+
49+
### If-None-Match
50+
51+
Used for conditional GET requests. Provide the `ETag` value from a previous response to avoid re-fetching unchanged data:
52+
53+
```http
54+
GET /MyTable/123
55+
If-None-Match: "abc123"
56+
```
57+
58+
If the record has not changed, Harper returns `304 Not Modified` with no body. This avoids serialization and network transfer overhead and works seamlessly with browser caches and external HTTP caches.
59+
60+
### Accept-Encoding
61+
62+
Harper supports standard HTTP compression. Including this header enables compressed responses:
63+
64+
```http
65+
Accept-Encoding: gzip, br
66+
```
67+
68+
Compression is particularly effective for JSON responses. For binary formats like CBOR, compression provides diminishing returns compared to the already-compact encoding.
69+
70+
### Authorization
71+
72+
Credentials for authenticating requests. See [Security Overview](../security/overview.md) for details on supported authentication mechanisms (Basic, JWT, mTLS).
73+
74+
### Sec-WebSocket-Protocol
75+
76+
When connecting via WebSocket for MQTT, the sub-protocol must be set to `mqtt` as required by the MQTT specification:
77+
78+
```http
79+
Sec-WebSocket-Protocol: mqtt
80+
```
81+
82+
## Content Type via URL Extension
83+
84+
As an alternative to the `Accept` header, content types can be specified using file-style extensions in the URL path:
85+
86+
```http
87+
GET /product/some-id.csv
88+
GET /product/.msgpack?category=software
89+
```
90+
91+
This is not recommended for production use — prefer the `Accept` header for clean, standard HTTP interactions.
92+
93+
## See Also
94+
95+
- [REST Overview](./overview.md) — HTTP methods and URL structure
96+
- [Content Types](./content-types.md) — Supported encoding formats
97+
- [Security Overview](../security/overview.md) — Authentication headers and mechanisms
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
---
2+
title: REST Overview
3+
---
4+
5+
<!-- Source: versioned_docs/version-4.7/developers/rest.md (primary) -->
6+
<!-- Source: versioned_docs/version-4.7/reference/components/built-in-extensions.md (rest plugin config options) -->
7+
<!-- Source: release-notes/v4-tucker/4.2.0.md (REST interface introduced) -->
8+
<!-- Source: release-notes/v4-tucker/4.5.0.md (URL path improvements, directURLMapping, record count removal) -->
9+
10+
# REST Overview
11+
12+
Added in: v4.2.0
13+
14+
Harper provides a powerful, efficient, and standard-compliant HTTP REST interface for interacting with tables and other resources. The REST interface is the recommended interface for data access, querying, and manipulation over HTTP, providing the best performance and HTTP interoperability with different clients.
15+
16+
## How the REST Interface Works
17+
18+
Harper's REST interface exposes database tables and custom resources as RESTful endpoints. Tables are **not** exported by default; they must be explicitly exported in a schema definition. The name of the exported resource defines the base of the endpoint path, served on the application HTTP server port (default `9926`).
19+
20+
For more on defining schemas and exporting resources, see [TODO:reference_versioned_docs/version-v4/database/schema.md 'Schema definition'].
21+
22+
## Configuration
23+
24+
Enable the REST interface by adding the `rest` plugin to your application's `config.yaml`:
25+
26+
```yaml
27+
rest: true
28+
```
29+
30+
**Options**:
31+
32+
```yaml
33+
rest:
34+
lastModified: true # enables Last-Modified response header support
35+
webSocket: false # disables automatic WebSocket support (enabled by default)
36+
```
37+
38+
## URL Structure
39+
40+
The REST interface follows a consistent URL structure:
41+
42+
| Path | Description |
43+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------- |
44+
| `/my-resource` | Root path — returns a description of the resource (e.g., table metadata) |
45+
| `/my-resource/` | Trailing slash indicates a collection — represents all records; append query parameters to search |
46+
| `/my-resource/record-id` | A specific record identified by its primary key |
47+
| `/my-resource/record-id/` | Trailing slash — the collection of records with the given id prefix |
48+
| `/my-resource/record-id/with/multiple/parts` | Record id with multiple path segments |
49+
50+
Changed in: v4.5.0 — Resources can be defined with nested paths and accessed by exact path without a trailing slash. The `id.property` dot syntax for accessing properties via URL is only applied to properties declared in a schema.
51+
52+
## HTTP Methods
53+
54+
REST operations map to HTTP methods following uniform interface principles:
55+
56+
### GET
57+
58+
Retrieve a record or perform a search. Handled by the resource's `get()` method.
59+
60+
```http
61+
GET /MyTable/123
62+
```
63+
64+
Returns the record with primary key `123`.
65+
66+
```http
67+
GET /MyTable/?name=Harper
68+
```
69+
70+
Returns records matching `name=Harper`. See [Querying](./querying.md) for the full query syntax.
71+
72+
```http
73+
GET /MyTable/123.propertyName
74+
```
75+
76+
Returns a single property of a record. Only works for properties declared in the schema.
77+
78+
#### Conditional Requests and Caching
79+
80+
GET responses include an `ETag` header encoding the record's version/last-modification time. Clients with a cached copy can include `If-None-Match` on subsequent requests. If the record hasn't changed, Harper returns `304 Not Modified` with no body — avoiding serialization and network transfer overhead.
81+
82+
### PUT
83+
84+
Create or replace a record with a specified primary key (upsert semantics). Handled by the resource's `put(record)` method. The stored record will exactly match the submitted body — any properties not included in the body are removed from the previous record.
85+
86+
```http
87+
PUT /MyTable/123
88+
Content-Type: application/json
89+
90+
{ "name": "some data" }
91+
```
92+
93+
Creates or replaces the record with primary key `123`.
94+
95+
### POST
96+
97+
Create a new record without specifying a primary key, or trigger a custom action. Handled by the resource's `post(data)` method. The auto-assigned primary key is returned in the `Location` response header.
98+
99+
```http
100+
POST /MyTable/
101+
Content-Type: application/json
102+
103+
{ "name": "some data" }
104+
```
105+
106+
### PATCH
107+
108+
Partially update a record, merging only the provided properties (CRDT-style update). Unspecified properties are preserved.
109+
110+
Added in: v4.3.0
111+
112+
```http
113+
PATCH /MyTable/123
114+
Content-Type: application/json
115+
116+
{ "status": "active" }
117+
```
118+
119+
### DELETE
120+
121+
Delete a specific record or all records matching a query.
122+
123+
```http
124+
DELETE /MyTable/123
125+
```
126+
127+
Deletes the record with primary key `123`.
128+
129+
```http
130+
DELETE /MyTable/?status=archived
131+
```
132+
133+
Deletes all records matching `status=archived`.
134+
135+
## Content Types
136+
137+
Harper supports multiple content types for both request bodies and responses. Use the `Content-Type` header for request bodies and the `Accept` header to request a specific response format.
138+
139+
See [Content Types](./content-types.md) for the full list of supported formats and encoding recommendations.
140+
141+
## OpenAPI
142+
143+
Added in: v4.3.0
144+
145+
Harper automatically generates an OpenAPI specification for all resources exported via a schema. This endpoint is available at:
146+
147+
```http
148+
GET /openapi
149+
```
150+
151+
## See Also
152+
153+
- [Querying](./querying.md) — Full URL query syntax, operators, and examples
154+
- [Headers](./headers.md) — HTTP headers used by the REST interface
155+
- [Content Types](./content-types.md) — Supported formats (JSON, CBOR, MessagePack, CSV)
156+
- [WebSockets](./websockets.md) — Real-time connections via WebSocket
157+
- [Server-Sent Events](./server-sent-events.md) — One-way streaming via SSE
158+
- [HTTP Server](../http/overview.md) — Underlying HTTP server configuration
159+
- [Database / Schema](TODO:reference_versioned_docs/version-v4/database/schema.md 'Schema definition') — How to define and export resources

0 commit comments

Comments
 (0)