.cursorrules (deprecated)
rules/api-design-rest/.cursorrules.cursorrules
Quality
69/100
Scores the file, not the repository.Length
1,025 words
28 headings · 8 code blocksRepository
16
— · pushed 109 days agoLast changed
2 days ago
First indexed 2 days ago.1# REST API Design — Cursor Rules2# Comprehensive rules for designing and implementing RESTful APIs34## Project Context5You are designing or maintaining a RESTful API. The API should follow REST principles,6use standard HTTP semantics, and provide a consistent, predictable interface for clients.7The API is versioned, documented, and designed for both internal and external consumption.89## Design Principles10- Resources are nouns, actions are HTTP methods11- Consistent and predictable URL patterns12- Standard HTTP status codes13- Meaningful error responses14- Pagination on all collection endpoints15- Versioning from day one16- HATEOAS where practical (links to related resources)1718## URL Design1920### Naming Conventions21- Use plural nouns for resources: `/users`, `/orders`, `/products`22- Use kebab-case for multi-word resources: `/order-items`, `/user-profiles`23- Use path parameters for identity: `/users/{id}`, `/orders/{orderId}/items/{itemId}`24- Use query parameters for filtering, sorting, pagination25- Nest resources for clear ownership: `/users/{id}/orders` (orders belonging to a user)26- Maximum nesting depth: 2 levels (e.g., `/users/{id}/orders/{orderId}`)2728### URL Patterns29```30GET /api/v1/users # List users (with pagination)31POST /api/v1/users # Create a user32GET /api/v1/users/{id} # Get a specific user33PUT /api/v1/users/{id} # Full update of a user34PATCH /api/v1/users/{id} # Partial update of a user35DELETE /api/v1/users/{id} # Delete a user3637GET /api/v1/users/{id}/orders # List orders for a user38POST /api/v1/users/{id}/orders # Create an order for a user3940# Filtering, sorting, pagination via query params41GET /api/v1/orders?status=pending&sort=-created_at&page=2&limit=204243# Search as a sub-resource or query param44GET /api/v1/products/search?q=laptop&category=electronics4546# Actions that don't map to CRUD — use verbs as sub-resources47POST /api/v1/orders/{id}/cancel48POST /api/v1/users/{id}/verify-email49```5051### What to Avoid52- Verbs in URLs: `/getUsers`, `/createOrder` (use HTTP methods instead)53- Singular resource names: `/user` instead of `/users`54- Deeply nested URLs: `/api/users/{id}/orders/{oid}/items/{iid}/reviews`55- File extensions: `/api/users.json` (use Accept header)56- Query parameters for resource identity: `/api/users?id=123`5758## HTTP Methods5960### Semantic Usage61| Method | Purpose | Idempotent | Safe | Request Body |62|--------|---------|------------|------|-------------|63| GET | Read resource(s) | Yes | Yes | No |64| POST | Create resource / trigger action | No | No | Yes |65| PUT | Full resource replacement | Yes | No | Yes |66| PATCH | Partial resource update | No* | No | Yes |67| DELETE | Remove a resource | Yes | No | Optional |6869### Rules70- GET must never modify server state71- POST for creation returns 201 with Location header72- PUT replaces the entire resource — omitted fields are reset73- PATCH updates only the provided fields74- DELETE returns 204 (no content) on success75- Use POST for actions that don't map to CRUD7677## Request and Response Format7879### Request Bodies80```json81// POST /api/v1/users82{83 "email": "alice@example.com",84 "name": "Alice Johnson",85 "role": "admin"86}8788// PATCH /api/v1/users/123 (only updated fields)89{90 "name": "Alice Smith"91}92```9394### Successful Responses95```json96// Single resource (GET /api/v1/users/123)97{98 "data": {99 "id": "123",100 "email": "alice@example.com",101 "name": "Alice Johnson",102 "role": "admin",103 "createdAt": "2025-01-15T10:30:00Z"104 }105}106107// Collection (GET /api/v1/users?page=2&limit=20)108{109 "data": [110 { "id": "123", "email": "alice@example.com", "name": "Alice Johnson" },111 { "id": "124", "email": "bob@example.com", "name": "Bob Smith" }112 ],113 "meta": {114 "page": 2,115 "limit": 20,116 "total": 156,117 "totalPages": 8118 }119}120121// Created resource (POST /api/v1/users — 201)122{123 "data": {124 "id": "125",125 "email": "carol@example.com",126 "name": "Carol Davis"127 }128}129// Headers: Location: /api/v1/users/125130```131132### Error Responses133```json134// 400 Bad Request (validation error)135{136 "error": {137 "code": "VALIDATION_ERROR",138 "message": "Invalid request data",139 "details": [140 { "field": "email", "message": "Must be a valid email address" },141 { "field": "name", "message": "Must be between 1 and 100 characters" }142 ]143 }144}145146// 404 Not Found147{148 "error": {149 "code": "NOT_FOUND",150 "message": "User with ID 999 not found"151 }152}153154// 409 Conflict155{156 "error": {157 "code": "CONFLICT",158 "message": "A user with this email already exists"159 }160}161```162163## Status Codes164165### Use Correctly166- **200** OK — Successful GET, PUT, PATCH, or DELETE167- **201** Created — Successful POST that creates a resource168- **204** No Content — Successful DELETE or update with no response body169- **400** Bad Request — Invalid input, validation failure170- **401** Unauthorized — Missing or invalid authentication171- **403** Forbidden — Authenticated but not authorized for this resource172- **404** Not Found — Resource does not exist173- **409** Conflict — Duplicate resource or state conflict174- **422** Unprocessable Entity — Valid JSON but semantically incorrect175- **429** Too Many Requests — Rate limit exceeded176- **500** Internal Server Error — Unexpected server failure177178## Pagination179180### Cursor-Based (Preferred for Large Datasets)181```182GET /api/v1/orders?limit=20&after=eyJpZCI6MTIzfQ183```184```json185{186 "data": [...],187 "meta": {188 "hasMore": true,189 "cursors": {190 "after": "eyJpZCI6MTQzfQ",191 "before": "eyJpZCI6MTI0fQ"192 }193 }194}195```196197### Offset-Based (Simpler but Slower on Large Data)198```199GET /api/v1/products?page=3&limit=20200```201202## Filtering and Sorting203```204GET /api/v1/orders?status=pending,shipped&created_after=2025-01-01&sort=-created_at,total205```206- Comma-separated values for OR filters207- Prefix with `-` for descending sort208- Use descriptive parameter names, not operator syntax209210## Versioning211- Use URL path versioning: `/api/v1/`, `/api/v2/`212- Never break existing API versions213- Deprecate old versions with headers: `Sunset: Sat, 01 Jan 2026 00:00:00 GMT`214- Version only when making breaking changes215216## Authentication and Authorization217- Use Bearer tokens in Authorization header: `Authorization: Bearer <token>`218- Return 401 for missing/invalid tokens, 403 for insufficient permissions219- Include rate limit headers: `X-RateLimit-Limit`, `X-RateLimit-Remaining`220- Use scopes or roles for fine-grained access control221222## Documentation223- Generate OpenAPI/Swagger spec from code annotations224- Document every endpoint with request/response examples225- Document error codes and their meanings226- Include authentication requirements per endpoint227- Provide curl examples for every endpoint228229## Common Pitfalls230- Using POST for everything instead of appropriate HTTP methods231- Returning 200 for errors (always use correct status codes)232- Inconsistent response format between endpoints233- Not paginating collection endpoints (returning unbounded lists)234- Exposing internal IDs or database structure in URLs235- Not versioning the API from the start236- Breaking changes without a new version237- Returning different response shapes for the same resource type238- Not setting Content-Type headers on responses239- Forgetting CORS headers for browser clients240
Also in survivorforge/cursor-rules
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| survivorforge/cursor-rulesrules/ai-ml-python/.cursorrules · 16 | .cursorrules | teststylearchdeployment+2 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/api-microservices/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 92/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/aws-serverless/.cursorrules · 16 | .cursorrules | teststylearchtypes+6 | 73/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/chrome-extension/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+4 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/clean-code/.cursorrules · 16 | .cursorrules | styledo-notagent-behaviourdocs | 57/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/database-sql/.cursorrules · 16 | .cursorrules | styletypessecuritydatabase+3 | 65/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/devops-docker/.cursorrules · 16 | .cursorrules | setupbuildteststyle+4 | 93/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/devops-infrastructure/.cursorrules · 16 | .cursorrules | buildteststylesecurity+3 | 93/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/django-rest/.cursorrules · 16 | .cursorrules | buildteststylearch+5 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/docker-devops/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 85/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/flutter-dart/.cursorrules · 16 | .cursorrules | teststylearchtypes+5 | 89/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/fullstack-nextjs-prisma/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 96/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/go-gin/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+5 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/go-production/.cursorrules · 16 | .cursorrules | teststylearchtesting-strategy+3 | 89/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/golang-api/.cursorrules · 16 | .cursorrules | buildteststylearch+6 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/langchain-ai/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+4 | 84/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mcp-server/.cursorrules · 16 | .cursorrules | testlint-formatstylearch+7 | 68/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mern-stack/.cursorrules · 16 | .cursorrules | setupteststylearch+6 | 81/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/mobile-react-native/.cursorrules · 16 | .cursorrules | teststylearchtypes+7 | 89/100 | 2 days ago | |
| survivorforge/cursor-rulesrules/nextjs-14-app-router/.cursorrules · 16 | .cursorrules | teststyletypestesting-strategy+3 | 71/100 | 2 days ago |
Diff against rules/ai-ml-python/.cursorrules Diff against rules/api-microservices/.cursorrules Diff against rules/aws-serverless/.cursorrules Diff against rules/chrome-extension/.cursorrules Diff against rules/clean-code/.cursorrules Diff against rules/database-sql/.cursorrules Diff against rules/devops-docker/.cursorrules Diff against rules/devops-infrastructure/.cursorrules Diff against rules/django-rest/.cursorrules Diff against rules/docker-devops/.cursorrules Diff against rules/flutter-dart/.cursorrules Diff against rules/fullstack-nextjs-prisma/.cursorrules Diff against rules/go-gin/.cursorrules Diff against rules/go-production/.cursorrules Diff against rules/golang-api/.cursorrules Diff against rules/langchain-ai/.cursorrules Diff against rules/mcp-server/.cursorrules Diff against rules/mern-stack/.cursorrules Diff against rules/mobile-react-native/.cursorrules Diff against rules/nextjs-14-app-router/.cursorrules
