API Starter Template
Simple Express API ready to extend. Minimal boilerplate for building serverless APIs.
Quick Start
Section titled “Quick Start”# Create projectstacksolo init --template api-starter
# Install dependenciescd my-apinpm install
# Start developmentnpm run devWhat’s Included
Section titled “What’s Included”- Express server on Cloud Functions
- Health check endpoint
- Echo endpoint for testing
- TypeScript + tsup build
Project Structure
Section titled “Project Structure”├── functions/api/│ └── src/│ └── index.ts # API routes
└── stacksolo.config.jsonAPI Endpoints
Section titled “API Endpoints”| Method | Path | Description |
|---|---|---|
| GET | /api/health | Health check |
| POST | /api/echo | Echo back request body |
Adding Endpoints
Section titled “Adding Endpoints”// Add to functions/api/src/index.ts
app.get('/api/users', async (req, res) => { // Your logic here res.json({ users: [] });});
app.post('/api/users', async (req, res) => { const { name, email } = req.body; // Create user res.json({ id: '123', name, email });});Adding Authentication
Section titled “Adding Authentication”To add Firebase Auth protection:
import { kernel } from '@stacksolo/runtime';
// Protect all routes under /api/protectedapp.use('/api/protected', kernel.authMiddleware());
app.get('/api/protected/profile', async (req, res) => { const { uid, email } = req.user!; res.json({ uid, email });});Adding a Database
Section titled “Adding a Database”To add PostgreSQL:
- Update
stacksolo.config.json:
{ "networks": [{ "databases": [{ "name": "main", "databaseVersion": "POSTGRES_15" }], "functions": [{ "name": "api", "env": { "DATABASE_URL": "@database/main.connectionString" } }] }]}- Install Drizzle:
npm install drizzle-orm postgresnpm install -D drizzle-kit- Create your schema and queries
Deployment
Section titled “Deployment”stacksolo deployThis creates:
- Cloud Functions API
- Load balancer with SSL