Quickstart

Start a Spica project on your machine, create your first bucket, read data over REST and serve your first function, in about ten minutes.

This guide runs Spica locally with the Spica CLI. The CLI starts the API, the admin panel, a database and an ingress as Docker containers, so you don't install anything else.

Before you begin

You need:

  • Docker running on your machine.
  • Node.js 20 or newer, to install the CLI.
  1. Install the CLI

    Terminal
    npm install -g @spica/cli
    spica --version
  2. Start a project

    Choose a name for your project and start it. The first run pulls the images, which takes a minute.

    Terminal
    spica project start my-app

    When the project is ready, the CLI prints where it is serving:

    Text
    Spica my-app is serving on http://localhost:4500.
    Open your browser on http://localhost:4500/dashboard to login.
    
    Identitifer: spica
    Password: spica

    The panel is served at http://localhost:4500 and the API at http://localhost:4500/api. If port 4500 is busy, the CLI picks a free port and tells you which one.

  3. Log in to the panel

    Open http://localhost:4500 and log in with the identifier spica and the password spica.

    The Spica panel login page with identifier and password fields
  4. Create a bucket

    Buckets hold your data. In the panel, open Buckets, click New Bucket and create a Posts bucket with a title (string) and a body (textarea) property. Then add a few entries with New Entry.

    You can do the same over the API. First get a token:

    Terminal
    curl -X POST http://localhost:4500/api/passport/identify \
      -H "Content-Type: application/json" \
      -d '{"identifier": "spica", "password": "spica"}'
    JSON
    {"scheme": "IDENTITY", "token": "eyJhbGciOi...", "issuer": "passport/identity"}

    Then create the bucket with that token:

    Terminal
    curl -X POST http://localhost:4500/api/bucket \
      -H "Authorization: IDENTITY <token>" \
      -H "Content-Type: application/json" \
      -d '{
        "title": "Posts",
        "description": "Blog posts",
        "primary": "title",
        "properties": {
          "title": {"type": "string", "title": "Title"},
          "body": {"type": "textarea", "title": "Body"}
        }
      }'
  5. Read and write data

    Use the bucket id from the response to insert and list entries:

    Terminal
    curl -X POST http://localhost:4500/api/bucket/<bucketId>/data \
      -H "Authorization: IDENTITY <token>" \
      -H "Content-Type: application/json" \
      -d '{"title": "Hello Spica", "body": "My first post"}'
    
    curl "http://localhost:4500/api/bucket/<bucketId>/data?limit=10" \
      -H "Authorization: IDENTITY <token>"
    JSON
    [{"_id": "6b0b1972a5611972c29c25fd", "title": "Hello Spica", "body": "My first post"}]

    On PostgreSQL the bucket and its entries are identified by id instead of _id. See MongoDB and PostgreSQL.

  6. Write a function

    Open Functions, click Add New Function, name it hello and add an HTTP trigger with method Get and path /hello. Replace the code with:

    index.mjs
    export default function (req, res) {
      const name = req.query.name ?? "world";
      return {message: `Hello, ${name}!`};
    }

    Save, then call it:

    Terminal
    curl "http://localhost:4500/api/fn-execute/hello?name=Ada"
    JSON
    {"message": "Hello, Ada!"}

Clean up

Stop and remove the project when you are done. Data is kept in Docker volumes unless you ask the CLI to remove them:

Terminal
spica project remove my-app --retain-volumes=false

Next steps