Tutorial: API Development

Build a robust REST API with authentication, validation, rate limiting, and documentation.

What You'll Build#

  • RESTful CRUD endpoints
  • API key authentication
  • Request validation with Zod
  • Rate limiting
  • Error handling
  • OpenAPI documentation

Prerequisites#

  • Next.js project with App Router
  • Prisma configured
  • Bootspring initialized

Time Required#

Approximately 35 minutes.

Step 1: Design the API#

Ask the api-expert:

Loading code block...

The agent provides:

  • Resource structure
  • Endpoint patterns
  • Authentication approach
  • Error handling strategy

Step 2: Apply API Skills#

Loading code block...

Step 3: Create API Key Authentication#

Database Schema#

Loading code block...

API Key Utilities#

Loading code block...

API Authentication Middleware#

Loading code block...

Step 4: Implement Rate Limiting#

Loading code block...

Install lru-cache:

Loading code block...

Rate Limit Middleware#

Loading code block...

Step 5: Create Validation Schemas#

Loading code block...

Step 6: Build CRUD Endpoints#

Tasks API#

Loading code block...

Single Task Endpoint#

Loading code block...

Step 7: Add Error Handling#

Loading code block...

Step 8: Create API Documentation#

Loading code block...

Step 9: Test the API#

Using curl#

Loading code block...

Verification Checklist#

  • API key authentication works
  • Rate limiting enforced
  • Validation errors return proper messages
  • CRUD operations work correctly
  • Pagination works
  • Error handling is consistent

Security Review#

Loading code block...

What You Learned#

  • API key authentication
  • Rate limiting implementation
  • Request validation with Zod
  • RESTful design patterns
  • Error handling strategies
  • OpenAPI documentation

Next Steps#