Loading...
Loading...
Use when designing API endpoints. Use when using wrong HTTP methods. Use when POST is used for reads.
npx skill4agent add yanko-belov/code-craft rest-conventionsNEVER use POST for read operations. NEVER put verbs in URLs.// ❌ VIOLATIONS
POST /getOrders // POST for read
POST /users/create // Verb in URL
GET /deleteUser?id=123 // GET for delete
POST /api/fetchProducts // Verb + wrong method// ✅ CORRECT: RESTful design
// Collections: plural nouns
GET /users // List users
POST /users // Create user
GET /users/:id // Get one user
PUT /users/:id // Replace user
PATCH /users/:id // Update user partially
DELETE /users/:id // Delete user
// Nested resources
GET /users/:id/orders // User's orders
POST /users/:id/orders // Create order for user
GET /orders/:id // Get specific order
// Filtering via query params
GET /orders?status=pending&userId=123
GET /products?category=electronics&limit=20| Method | Use For | Idempotent | Safe |
|---|---|---|---|
| GET | Read/fetch | Yes | Yes |
| POST | Create | No | No |
| PUT | Replace entirely | Yes | No |
| PATCH | Partial update | Yes | No |
| DELETE | Remove | Yes | No |
GET /orders?status=pending
GET /products?minPrice=10&maxPrice=100
GET /users?role=admin&active=trueGET /orders?page=2&limit=20
GET /orders?cursor=abc123&limit=20GET /products?sort=price:asc
GET /users?sort=createdAt:descPOST /orders/:id/cancel // Action on order
POST /users/:id/verify // Action on user
POST /payments/:id/refund // Action on paymentGET /orders?userId=123POST /getOrdersPOST /search/getUser/createOrder| Bad | Good |
|---|---|
| |
| |
| |
| |
| |
| Excuse | Reality |
|---|---|
| "POST is simpler" | Same code, better semantics. |
| "Need request body" | Use query parameters. |
| "GET URLs too long" | Paginate or use search endpoint. |
| "That's how we do it" | New code should be correct. |
| "Doesn't matter" | Caching, bookmarking, tools all depend on it. |