API Lab · class day 50 and 51
The API automation framework
The whole API in one place: the target of the framework you build in the last two classes.
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 |
| POST | /api/v1/echo{"hello": "world", "list": [1, 2, 3]} | Sends back method, query, headers and body, and the body as JSON when it is JSON | 200 OK, 413 Body too big |
| PUT | /api/v1/echo{"a": 1} | The same as POST: PUT, PATCH and DELETE are echoed too | 200 OK |
| GET | /api/v1/echo/headers | The headers your request sent. The answer has a header X-Practice-Header | 200 OK |
| GET | /api/v1/cookies/set?name={name}&value={value} | Answers with a Set-Cookie header | 200 OK, 400 Bad request |
| GET | /api/v1/cookies | The cookies your request sent | 200 OK |
| GET | /api/v1/cookies/delete?name={name} | Tells the client to forget a cookie | 200 OK, 400 Bad request |
| GET | /api/v1/search?q={text} | Search user names. Query: q (required), sort (name, -name, id, -id), page, limit | 200 OK, 400 Bad request |
| GET | /api/v1/users/{id}/orders | The orders of a user (user 1 has two to start with) | 200 OK, 400 Bad request, 404 Not found |
| GET | /api/v1/users/{id}/orders/{orderId} | One order of a user. Two path parameters | 200 OK, 400 Bad request, 404 Not found |
| GET | /api/v1/books | Nested JSON: library, books, authors, tags, publisher. Query: tag, inStock | 200 OK |
| GET | /api/v1/books/{id} | One book | 200 OK, 400 Bad request, 404 Not found |
| GET | /api/v1/books.xml | The same books as XML | 200 OK |
| GET | /api/v1/books | Send the header Accept: application/xml and /books answers with XML | 200 OK |
| GET | /api/v1/files | The downloadable files with size and SHA-256 checksum | 200 OK |
| GET | /api/v1/files/{name} | Download sample.txt, numbers.csv or logo.png | 200 OK, 404 Not found |
| POST | /api/v1/files | Upload a file (multipart/form-data, a part named file, at most 1 MB). It is described and forgotten | 201 Created, 400 Bad request, 413 Body too big, 415 Unsupported media type |
| GET | /api/v1/schemas/user.json | JSON schema of one user | 200 OK |
| GET | /api/v1/schemas/users-list.json | JSON schema of a page of users | 200 OK |
| GET | /api/v1/schemas/books.xsd | XML schema (XSD) of /books.xml | 200 OK |
| GET | /api/v1/secure/basic | Basic authentication: user student, password Learn@123 | 200 OK, 401 Unauthorized |
| POST | /api/v1/auth/token{"username": "student", "password": "Learn@123"} | Log in with JSON and get a bearer token (valid for one hour) | 200 OK, 400 Bad request, 401 Unauthorized |
| POST | /api/v1/oauth/token | OAuth 2 client credentials. Form fields: grant_type=client_credentials, client_id=lab-client, client_secret=lab-secret | 200 OK, 400 Bad request, 401 Unauthorized |
| GET | /api/v1/secure/bearer | Needs the header Authorization: Bearer <token> | 200 OK, 401 Unauthorized |
| GET | /api/v1/secure/apikey | Needs the header X-API-Key: lab-key-123. Missing = 401, wrong = 403 | 200 OK, 401 Unauthorized, 403 Forbidden |
| POST | /api/v1/users/{id}/orders{"product": "Webcam", "quantity": 2} | Create an order for a user: product and quantity (1 to 10; a sandbox holds at most 200 orders) | 201 Created, 400 Bad request, 404 Not found, 409 Conflict |
| DELETE | /api/v1/users/{id}/orders/{orderId} | Delete an order | 204 No content, 400 Bad request, 404 Not found |