Build a REST API

Create a complete REST API for case management with tables, endpoints, and CRUD operations.

Build a REST API

Create a cases API with full CRUD operations — from database table to tested endpoints — in about 10 minutes.

What you will build

A cases API with five endpoints:

- GET /api/cases — list all cases
- GET /api/cases/:id — get a single case
- POST /api/cases — create a case
- PUT /api/cases/:id — update a case
- DELETE /api/cases/:id — delete a case

Steps

Create the cases table

Open the Database screen and create a new table called cases with these columns:

| Column | Type | Notes |
    |--------|------|-------|
    | id | UUID | Primary key |
    | case_number | Text | Required, unique external reference |
    | case_name | Text | Required client-facing title |
    | description | Text | Summary of the matter |
    | status | Text | e.g., open, review, closed |
    | created_at | Timestamp | Default: now() |

Create the list endpoint

Go to Endpoints and create GET /api/cases. In the function editor, add two steps:

1. Database Select — Table: cases, Order By: created_at DESC, Assign To: cases
    2. Respond — Status: 200, Body: { data: vars.cases }

Expected response:

{ "data": [{ "id": "8b6f2f8a-1c5a-4f3d-9b3f-9f9a8d1a2345", "case_number": "CASE-1042", "case_name": "Contract Review", "status": "open" }] }

Create the get-by-id endpoint

Create GET /api/cases/:id with this function:

1. Find One — Table: cases, Where: { id: params.id }, Assign To: caseRecord
    2. If/Else — Condition: vars.caseRecord == null
       - True: Respond — Status: 404, Body: { error: 'Case not found' }
       - False: Respond — Status: 200, Body: { data: vars.caseRecord }

Create the create endpoint

Create POST /api/cases:

1. Database Insert — Table: cases, Data: input, Returning: *, Assign To: newCase
    2. Respond — Status: 201, Body: { data: vars.newCase }

Send this body to test:

{ "case_number": "CASE-1043", "case_name": "New Client Intake", "status": "open" }

Create update and delete endpoints

Create PUT /api/cases/:id with a Database Update step (Where: { id: params.id }, Data: input) and a Respond step.

Create DELETE /api/cases/:id with a Database Delete step (Where: { id: params.id }) and a Respond step returning status 204.

Test in the Playground

Open the Playground screen. Select POST /api/cases, enter a JSON body, and click Send. Then select GET /api/cases and verify your case appears in the list.

Pro tip

Add input validation by inserting an If/Else step before the database insert to check that input.case_number exists.

Advanced CRUD
/guides/crud-operations
Add pagination, filtering, and sorting
Add User Authentication
/guides/user-auth
Protect your endpoints with JWT tokens
API Playground
/features/playground
Test your endpoints in the browser