Skip to content

API Development Patterns

Master API development with Cursor IDE and Claude Code. These patterns cover REST, GraphQL, gRPC, API design principles, versioning strategies, security, documentation, and testing approaches optimized for AI-assisted development.

  1. Open Cursor in your project
  2. Activate Agent mode (Cmd/Ctrl + I)
  3. Prompt: “Design RESTful API for task management with:
    • Resource-based URLs
    • Proper HTTP methods
    • Status codes
    • HATEOAS links
    • Pagination
    • Filtering and sorting”
  4. Agent creates complete API specification
# API design prompt:
"Design REST resources for blog platform:
- Hierarchical resources (/blogs/{id}/posts/{id}/comments)
- Resource relationships
- Consistent naming conventions
- Action endpoints for non-CRUD
- Bulk operations
- Async operations with status endpoints"

Hypermedia

// Prompt: "Add HATEOAS links:
// - Resource navigation
// - Available actions
// - Related resources
// - Pagination links"

Content Negotiation

# Prompt: "Implement content negotiation:
# - Multiple response formats
# - Language selection
# - Version negotiation
# - Compression support"
# GraphQL schema prompt:
"Design GraphQL schema for social network:
- User types with relationships
- Query complexity limiting
- Dataloader for N+1 prevention
- Subscription for real-time updates
- Custom scalars
- Federation support"
// Resolver optimization prompt:
"Optimize GraphQL resolvers with:
- Batch loading
- Caching strategies
- Query depth limiting
- Field-level permissions
- Error handling"
// gRPC service prompt:
"Create gRPC service for payment processing:
- Protocol buffer definitions
- Service methods (unary, streaming)
- Error handling with status codes
- Interceptors for auth/logging
- Health checking
- Load balancing support"
  1. Streaming: “Implement bidirectional streaming for chat”
  2. Interceptors: “Add auth and logging interceptors”
  3. Error Handling: “Create rich error details”
  4. Performance: “Optimize with connection pooling”
// Versioning implementation prompt:
"Implement API versioning with:
- URL versioning (/v1/, /v2/)
- Header versioning
- Content negotiation
- Sunset headers
- Migration guides
- Backward compatibility"

Version Management

AI can help with:

  • Deprecation strategies
  • Version migration paths
  • Feature flags for gradual rollout
  • Client compatibility detection
  • Documentation updates
// OAuth implementation prompt:
"Implement OAuth 2.0 with:
- Authorization code flow
- Refresh token rotation
- PKCE for public clients
- Scope management
- Token introspection
- Revocation endpoints"
// JWT implementation:
"Set up JWT auth with:
- Token generation
- Claims validation
- Refresh strategy
- Blacklisting
- Key rotation"
// Rate limiting prompt:
"Implement rate limiting with:
- Token bucket algorithm
- Sliding window counters
- Distributed rate limiting
- User-based limits
- Endpoint-specific limits
- Graceful degradation"
# Documentation prompt:
"Generate OpenAPI documentation with:
- Complete schema definitions
- Request/response examples
- Authentication details
- Error responses
- Webhook specifications
- Testing endpoints"

Interactive Docs

// Prompt: "Create Swagger UI with:
// - Try-it-out functionality
// - Code generation
// - Multiple languages
// - Environment switching"

SDK Generation

// Prompt: "Generate client SDKs:
// - TypeScript/JavaScript
// - Python
// - Go
// - Java
// With proper error handling"
// Error handling prompt:
"Design error response format:
{
'error': {
'code': 'RESOURCE_NOT_FOUND',
'message': 'User not found',
'details': {...},
'timestamp': '2024-01-01T00:00:00Z',
'traceId': 'abc123'
}
}
Include:
- Standard error codes
- Localized messages
- Debug information
- Recovery suggestions"
# Offset pagination:
"Implement offset pagination:
- Page and limit parameters
- Total count in response
- Link headers
- Max limit enforcement"
// Webhook system prompt:
"Create webhook system with:
- Event registration
- Payload signing
- Retry logic
- Dead letter queue
- Event filtering
- Delivery tracking"
  1. Design Events: “Define event schema and types”
  2. Implement Delivery: “Create reliable delivery system”
  3. Add Security: “Implement HMAC signature verification”
  4. Monitor Health: “Track delivery success rates”
// API testing prompt:
"Create API test suite with:
- Contract testing
- Integration tests
- Load testing
- Security testing
- Mock services
- Test data management"

Test Automation

AI can generate:

  • Postman collections
  • Newman CI integration
  • Pact contract tests
  • K6 performance tests
  • Security scan configs
# Caching implementation:
"Implement HTTP caching with:
- ETag generation
- Cache-Control headers
- Conditional requests
- CDN integration
- Cache invalidation
- Vary headers"
// Monitoring prompt:
"Set up API monitoring with:
- Request/response logging
- Performance metrics
- Error tracking
- Usage analytics
- SLA monitoring
- Alerting rules"
# API gateway prompt:
"Configure API gateway for:
- Request routing
- Authentication
- Rate limiting
- Request/response transformation
- Circuit breaking
- Service discovery"
// Structure prompts like:
"Design [REST/GraphQL/gRPC] API for [domain] with:
- Use cases: [list specific operations]
- Performance requirements: [SLA]
- Security needs: [auth method]
- Integration points: [external services]
- Include examples and edge cases"

Design Review

AI can review for:

  • RESTful principles
  • Security vulnerabilities
  • Performance issues
  • Documentation gaps

Code Generation

AI can generate:

  • API clients
  • Server stubs
  • Test suites
  • Documentation
// Event-driven API:
"Implement event-driven API with:
- Server-sent events
- WebSocket support
- Event sourcing
- CQRS pattern
- Event replay
- Schema registry"
// API composition pattern:
"Create API composition layer:
- Backend for frontend (BFF)
- Service aggregation
- Response transformation
- Fallback strategies
- Cache coordination"