Creating a REST API

A complete resource API with list, read, create, update, and delete — proper methods, statuses, validation, and scopes.

This tutorial builds a full REST resource: GET/POST /api/v1/tasks and GET/PUT/DELETE /api/v1/tasks/{guid}. It assumes the quickstart — if you haven't registered an endpoint before, do Build Your First API first.

The Shape of a Resource

Operation Method + URI Success status
ListGET /api/v1/tasks200 + array
CreatePOST /api/v1/tasks201 + created document
Read oneGET /api/v1/tasks/{guid}200 + document, 404 if unknown
UpdatePUT /api/v1/tasks/{guid}200 + updated document, 404 if unknown
DeleteDELETE /api/v1/tasks/{guid}200 or 204, 404 if unknown

Each row is one API block (on_startup_register_uri_get, _post, _put, _delete) feeding one handler function — the same trigger → work → reply shape from Block Templates.

GET /tasks — List with Filters

  1. Trigger on_startup_register_uri_get with URI tasks → handler function.
  2. Build the query: optional status param from httpconnection_get_paramsquery_bool_term_fieldsquery_bool_filterquery_and, with query_sort_field on _meta.created descending.
  3. function_search on the tasks storage; respect limit/offset params for pagination.
  4. Reply with httpconnection_set_json: code 200, data = the results array.

POST /tasks — Create with Validation

  1. Trigger on_startup_register_uri_post with URI tasks.
  2. Validate required fields from the request body with condition_not_empty_value per field → branch; on the false path reply 400 with {"error": "title is required"} (see validation template).
  3. Map the body to document fields with mutations_set_bp_field_multiple, then function_create_document_from_mutations.
  4. Reply 201 with the created document (it now has its _meta.guid).

GET /tasks/{guid} — Read One

  1. The URI block exposes the guid as a param; fetch with function_get_document on the tasks storage.
  2. On its found condition: reply 200 with the document. Otherwise: reply 404 with {"error": "not found"} — wire both paths from the success/error pins (see error handling).

PUT and DELETE

  • PUT — same fetch-first guard, then function_update_document_mutations with the changed fields. Reply 200 with the updated document; 404 when missing.
  • DELETE — soft-delete with function_remove_document (recoverable), or hard-delete with function_delete_document when you mean it — see document lifecycle. Reply 200 with a small confirmation object.

Scopes and Testing

  • Scope the collection endpoints with the lock icon: *public for open reads, *loggedin or a custom scope for writes — see Remote Access Control.
  • Activate the blueprint, then test every row of the table with curl — commands in API workflows.
  • When the endpoint 404s right after activation, it's almost always a scope or an inactive blueprint — see Common Issues.

Next Steps

API Guide Conventions, error codes, and rate limits for your API. Storages The queries and mutations behind every row of the table. Block Templates The endpoint and validation shapes in one view.