Skip to content

Latest commit

 

History

History
103 lines (78 loc) · 2.77 KB

File metadata and controls

103 lines (78 loc) · 2.77 KB

Quickstart

Zero to first API call in 5 minutes. This guide uses Docker Compose and makes every choice for you. For more options, see Getting Started.

Quickstart walkthrough — from docker compose to first API call

1. Create docker-compose.yml

services:
  snaapi:
    image: ghcr.io/snaapi/snaapi:latest
    ports:
      - "8000:8000"
    environment:
      DATABASE_URL: "postgres://snaapi:snaapi@db:5432/snaapi"
      BETTER_AUTH_SECRET: "change-me-to-something-random"
      BETTER_AUTH_URL: "http://localhost:8000"
      SNAAPI_SESSION_SECRET: "change-me-to-something-random"
      SNAAPI_AUTO_MIGRATE: "true"
      SNAAPI_INSTALL_TOKEN: "my-setup-token"
    depends_on:
      - db

  db:
    image: postgres:15
    environment:
      POSTGRES_USER: snaapi
      POSTGRES_PASSWORD: snaapi
      POSTGRES_DB: snaapi
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

2. Start Snaapi

docker compose up -d

Wait a few seconds for PostgreSQL and Snaapi to start, then open http://localhost:8000 in your browser.

3. Set up your account

  1. Enter your install token (my-setup-token from the compose file above).
  2. Create an admin account with your name, email, and password.

You are now logged into the Admin Console.

4. Create a resource

  1. Click Add Resource.
  2. Name it tasks.
  3. Add two fields:
    • title -- type string, toggle required on
    • done -- type boolean
  4. Save the resource.

Snaapi creates the database table and REST endpoints automatically.

5. Get an API key

curl -X POST http://localhost:8000/token \
  -H "Content-Type: application/json" \
  -d '{"email":"your@email.com","password":"your-password"}'

Copy the token from the response (it starts with sna_).

6. Create a record

curl -X POST http://localhost:8000/v1/tasks \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sna_YOUR_TOKEN" \
  -d '{"title": "Buy groceries", "done": false}'

7. Read your records

curl http://localhost:8000/v1/tasks \
  -H "Authorization: Bearer sna_YOUR_TOKEN"

You should see a JSON array containing the task you just created.

Next steps

  • Getting Started -- binary install, manual PostgreSQL setup, and full configuration
  • Resources -- system fields, soft delete, and resource settings
  • Fields -- all 10 field types, validation, and generated values
  • Tutorials -- build a blog API, multi-tenant SaaS, and more