Skip to main content
This tutorial builds a posts API end-to-end: creating posts, uploading cover images, and processing a signed webhook. It uses the current EdgeSpark scaffold and CLI workflow. What you’ll build:
  • POST /api/posts to create a post
  • GET /api/public/posts to list published posts
  • GET /api/posts/:id to read one post
  • POST /api/upload-url to issue a presigned R2 upload URL
  • POST /api/webhooks/notify to accept a signed webhook

Step 1: Define your schema

Edit server/src/defs/db_schema.ts:
server/src/defs/db_schema.ts
Generate and apply the migration:

Step 2: Declare a storage bucket

Edit server/src/defs/storage_schema.ts:
server/src/defs/storage_schema.ts
Apply the bucket declaration:

Step 3: Declare and register a secret

First allow the key in server/src/defs/runtime.ts:
server/src/defs/runtime.ts
Then register it:
Follow the secure project URL printed by the CLI and enter the value in the browser.

Step 4: Write the server routes

Replace server/src/index.ts:
server/src/index.ts

Step 5: Deploy your project

Test the public endpoint:
New projects currently deploy to one default production environment. Public staging support is coming soon.

Step 6: Upload from the client

Use your frontend to request a presigned upload URL, then upload directly to R2:
web/src/upload.ts

See also

Use the database

Define schema, generate migrations, and query D1 in the current scaffold.

Use storage

Declare buckets, apply them with the CLI, and use presigned upload URLs.
Last modified on April 9, 2026