Mutations
Declare a schema-backed endpoint with a write method to change its table. POST creates a row, PATCH (or PUT) updates one by id, and DELETE removes one by id.
How it works
The request body is a JSON object. Keys that match a real column are written; everything else - including any client-supplied id, which is server-assigned - is ignored. Use status: to choose the success code (201 for create, 204 for delete).
Writes go to the same SQLite store the reads use, so a created row is immediately visible to a follow-up GET.
Create
A POST to a collection inserts a row from the body and returns it.
- path: /posts
method: POST
response:
schema: Post
status: 201 curl -XPOST http://localhost:3000/posts -d '{"title":"Hi","authorId":1}'
# => 201 {"id": 4, "title": "Hi", "authorId": 1, ...} Update
A PATCH (or PUT) to /:id updates the matching row and returns it, or 404 if the id doesn't exist.
- path: /posts/:id
method: PATCH # PUT behaves the same
response:
schema: Post curl -XPATCH http://localhost:3000/posts/4 -d '{"title":"Edited"}'
# => 200 {"id": 4, "title": "Edited", ...} Delete
A DELETE to /:id removes the row, or returns 404 if it doesn't exist. With status: 204 the response is empty; any other status returns {"deleted": <id>}.
- path: /posts/:id
method: DELETE
response:
schema: Post
status: 204 curl -XDELETE http://localhost:3000/posts/4
# => 204, empty body
curl http://localhost:3000/posts/4
# => 404 {"error": "Not found"} Common mistakes
Sending a malformed body
A body that isn't valid JSON is rejected before it touches the database:
curl -XPOST http://localhost:3000/posts -d 'not json'
# => 400 {"error": "Invalid JSON body"} Violating a relationship
A foreign key that points at a row which doesn't exist fails the constraint and returns 400:
curl -XPOST http://localhost:3000/posts -d '{"title":"x","authorId":999}'
# => 400 Both responses are customizable like any other error. See Errors.