Buckets

Buckets are schema-defined collections of documents with ready-made REST, GraphQL and realtime APIs, validation, rules, localization and history.

A bucket is a collection of documents that share a schema. When you create a bucket, Spica immediately serves:

  • A REST API to list, read, create, replace, patch and delete documents.
  • A realtime WebSocket stream that pushes inserts, updates and deletes to subscribers.
  • A GraphQL schema, when GraphQL is enabled.
  • A data entry UI in the admin panel, generated from the schema.

Every write is validated against the schema. Every read can be filtered, sorted, paginated, localized and joined with related buckets.

The Posts bucket in the panel, showing entries in a table with title, slug, body, status and tags columns
A bucket in the panel

A first look

A bucket definition is JSON. This one describes blog posts:

Posts bucket
{
  "title": "Posts",
  "description": "Blog posts",
  "primary": "title",
  "history": true,
  "properties": {
    "title": {"type": "string", "title": "Title", "options": {"translate": true}},
    "slug": {"type": "string", "title": "Slug", "pattern": "^[a-z0-9-]+$"},
    "status": {"type": "string", "title": "Status", "enum": ["draft", "published"], "default": "draft"},
    "author": {"type": "relation", "title": "Author", "bucketId": "<authorsBucketId>", "relationType": "onetoone"},
    "created_at": {"type": "date", "title": "Created at", "default": ":created_at", "readOnly": true}
  },
  "required": ["title", "slug"],
  "acl": {"read": "document.status == \"published\"", "write": "false == true"}
}

And this is how an app reads published posts with their authors, in Turkish:

Terminal
curl "https://api.example.com/api/bucket/<postsBucketId>/data?relation=author&limit=10" \
  -H "Authorization: USER <token>" \
  -H "Accept-Language: tr_TR"

In this section

Who can access bucket data

Access is checked in two layers:

  1. Policies decide whether the caller may use an endpoint on a bucket at all, for example bucket:data:index on the Posts bucket.
  2. Rules decide which documents a USER may read or write. Identities and API keys skip rules.

See Rules and Policies.