Guides
Build a Serverless REST API
Step-by-step guide to building a production-ready serverless REST API with storage and queues.
This guide walks through building a production-ready serverless REST API with object storage and background message queue processing.
What You'll Build
- An HTTP POST endpoint that accepts order data
- S3 storage for persisting order receipts
- SQS queue for asynchronous order processing
- A health check GET endpoint
Prerequisites
- NovaServe CLI installed (Installation Guide)
- AWS credentials configured
- Node.js 18+
Complete Implementation
App.ts
1import { defineApp, api, storage, queue } from "novaserve";23export const app = defineApp({4 name: "order-management-service",5 region: "us-east-1",6});78// 1. Storage bucket for order receipts9export const orderStorage = storage("order-receipts-bucket", {10 public: false,11});1213// 2. Message queue for async order processing14export const orderQueue = queue("order-processing-queue");1516// 3. Health check endpoint17export const healthApi = api.get("/health", async () => {18 return {19 status: "healthy",20 timestamp: new Date().toISOString(),21 version: "1.0.0",22 };23});2425// 4. Create order endpoint26export const createOrderApi = api.post("/api/v1/orders", async (req) => {27 const body = await req.json();2829 if (!body.customerEmail || !body.items?.length) {30 return new Response(31 JSON.stringify({ error: "Missing customerEmail or items" }),32 { status: 400 }33 );34 }3536 const orderId = `ord-${Date.now()}`;37 const orderPayload = {38 orderId,39 customerEmail: body.customerEmail,40 items: body.items,41 createdAt: new Date().toISOString(),42 };4344 // Store receipt in object storage45 await orderStorage.put(46 `receipts/${orderId}.json`,47 JSON.stringify(orderPayload)48 );4950 // Dispatch to processing queue51 await orderQueue.push({52 event: "ORDER_CREATED",53 orderId,54 customerEmail: body.customerEmail,55 });5657 return { status: 201, orderId };58});Local Development & Testing
Terminal
nova devTest the health check:
Terminal
curl http://localhost:3000/healthSubmit a test order:
Terminal
curl -X POST http://localhost:3000/api/v1/orders \
-H "Content-Type: application/json" \
-d '{"customerEmail": "user@example.com", "items": [{"id": "item-1", "price": 49.99}]}'Deploy to AWS
Terminal
nova deploy --target awsNovaServe automatically compiles your AST, synthesizes IAM permissions for s3:PutObject and sqs:SendMessage, and provisions API Gateway v2 + Lambda endpoints.