API Lab · class day 43
HTTP methods and status codes
Every HTTP method on one resource (users), and an address that answers with any status code you ask for.
Send X-Sandbox: your-name with every request to get your own data. Addresses start with /api/v1 after this site's address.
Addresses for today
| Method | Address | What it does | Status codes |
|---|---|---|---|
| GET | /api/v1/users | A page of users. Query: page, limit (1 to 20), job | 200 OK, 400 Bad request |
| GET | /api/v1/users/{id} | One user | 200 OK, 400 Bad request, 404 Not found |
| POST | /api/v1/users{"name": "Asha Rao", "email": "asha@example.com", "job": "Tester"} | Create a user (name and email are required, the email must be new; a sandbox holds at most 100 users) | 201 Created, 400 Bad request, 409 Conflict, 415 Unsupported media type |
| PUT | /api/v1/users/{id}{"name": "Asha Rao", "email": "asha@example.com", "job": "Tester"} | Replace a user: send name and email | 200 OK, 400 Bad request, 404 Not found, 409 Conflict |
| PATCH | /api/v1/users/{id}{"job": "Senior Tester"} | Change only the fields you send | 200 OK, 400 Bad request, 404 Not found, 409 Conflict |
| DELETE | /api/v1/users/{id} | Delete a user (and the orders of that user) | 204 No content, 400 Bad request, 404 Not found |
| GET | /api/v1/status/{code} | Answers with that status code. Works with GET, POST, PUT, PATCH and DELETE | 200 OK, 201 Created, 202 Accepted, 204 No content, 301 Moved permanently, 400 Bad request, 401 Unauthorized, 403 Forbidden, 404 Not found, 405 Method not allowed, 409 Conflict, 415 Unsupported media type, 422 Unprocessable, 429 Too many requests, 500 Server error, 502 Bad gateway, 503 Service unavailable |
| GET | /api/v1/sandbox | Which sandbox you are in and what it holds | 200 OK |
| DELETE | /api/v1/sandbox | Forget your changes and start again from the 12 users | 204 No content |