Scaffold a complete REST API with CRUD operations
✓Works with OpenClaudeYou are a backend API scaffolding expert. The user wants to generate a complete REST API structure with CRUD operations for a resource.
What to check first
- Verify Node.js version with
node --version(v14+ required) - Check if Express.js is installed with
npm list express - Confirm you have a package.json file in your project root
Steps
- Install Express.js and required middleware:
npm install express body-parser cors uuid - Create a
server.jsfile in your project root to define the Express app and port configuration - Define a data model by creating a
modelsdirectory and adding a resource schema (e.g.,User.js) - Create a
routesdirectory and build a resource router file (e.g.,userRoutes.js) that handles all HTTP methods - Implement GET (all), GET (by id), POST (create), PUT (update), and DELETE (remove) handlers in the router
- Use a simple in-memory array or Map for storage to avoid database setup
- Mount the router in
server.jsusingapp.use('/api/users', userRoutes) - Start the server with
node server.jsand test endpoints using curl or Postman
Code
// server.js
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const { v4: uuidv4 } = require('uuid');
const app = express();
const PORT = 3000;
// Middleware
app.use(cors());
app.use(bodyParser.json());
// In-memory storage
let users = [
{ id: uuidv4(), name: 'Alice', email: 'alice@example.com' },
{ id: uuidv4(), name: 'Bob', email: 'bob@example.com' }
];
// CRUD Routes
// GET all users
app.get('/api/users', (req, res) => {
res.json(users);
});
// GET user by ID
app.get('/api/users/:id', (req, res) => {
const user = users.find(u => u.id === req.params.id);
if (!user) return res.status(404).json({ error: 'User not found' });
res.json(user);
});
// POST create new user
app.post('/api/users', (req, res) => {
const { name, email } = req.body;
if (!name || !email) {
return res.status(400).json({ error: 'Name and email required' });
}
const newUser = { id: uuidv4(), name, email };
users.push(newUser);
res.status(201).json(newUser);
});
// PUT update user
app.put('/api/users/:id', (req, res) => {
const user =
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Not validating request bodies before processing — attackers will send malformed payloads to crash your service
- Returning detailed error messages in production — leaks internal architecture to attackers
- Forgetting CORS headers — frontend will silently fail with cryptic browser errors
- Hardcoding API keys in code — use environment variables and secret management
- No rate limiting — one client can DoS your entire API
When NOT to Use This Skill
- When a single shared library would suffice — APIs add network latency and failure modes
- For internal-only data flow within the same process — use direct function calls
- When you need transactional consistency across services — APIs can't guarantee this without distributed transactions
How to Verify It Worked
- Test all CRUD operations end-to-end including error cases (404, 401, 403, 500)
- Run an OWASP ZAP scan against your API — catches common security issues automatically
- Load test with k6 or Artillery — verify your API holds up under realistic traffic
- Verify rate limits actually trigger when exceeded — they often don't due to misconfiguration
Production Considerations
- Version your API from day one (
/v1/) — breaking changes are inevitable, give yourself a path - Set request size limits — prevents memory exhaustion attacks
- Add structured logging with request IDs — trace every request across your stack
- Document your API with OpenAPI — generates client SDKs and interactive docs for free
Related API Development Skills
Other Claude Code skills in the same category — free to download.
GraphQL Schema Generator
Generate GraphQL schema from existing data models
API Documentation
Generate OpenAPI/Swagger documentation from code
API Versioning
Implement API versioning strategy
Rate Limiter
Add rate limiting to API endpoints
API Error Handler
Create standardized API error handling
Request Validator
Add request validation middleware (Zod, Joi)
API Response Formatter
Standardize API response format
Webhook Handler
Create webhook endpoint with signature verification
Want a API Development skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.