Practice Lab

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

MethodAddressWhat it doesStatus codes
GET/api/v1/usersA page of users. Query: page, limit (1 to 20), job200 OK, 400 Bad request
GET/api/v1/users/{id}One user200 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 email200 OK, 400 Bad request, 404 Not found, 409 Conflict
PATCH/api/v1/users/{id}
{"job": "Senior Tester"}
Change only the fields you send200 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 DELETE200 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/sandboxWhich sandbox you are in and what it holds200 OK
DELETE/api/v1/sandboxForget your changes and start again from the 12 users204 No content