Practice Lab

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

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
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 JSON200 OK, 413 Body too big
PUT/api/v1/echo
{"a": 1}
The same as POST: PUT, PATCH and DELETE are echoed too200 OK
GET/api/v1/echo/headersThe headers your request sent. The answer has a header X-Practice-Header200 OK
GET/api/v1/cookies/set?name={name}&value={value}Answers with a Set-Cookie header200 OK, 400 Bad request
GET/api/v1/cookiesThe cookies your request sent200 OK
GET/api/v1/cookies/delete?name={name}Tells the client to forget a cookie200 OK, 400 Bad request
GET/api/v1/search?q={text}Search user names. Query: q (required), sort (name, -name, id, -id), page, limit200 OK, 400 Bad request
GET/api/v1/users/{id}/ordersThe 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 parameters200 OK, 400 Bad request, 404 Not found
GET/api/v1/booksNested JSON: library, books, authors, tags, publisher. Query: tag, inStock200 OK
GET/api/v1/books/{id}One book200 OK, 400 Bad request, 404 Not found
GET/api/v1/books.xmlThe same books as XML200 OK
GET/api/v1/booksSend the header Accept: application/xml and /books answers with XML200 OK
GET/api/v1/filesThe downloadable files with size and SHA-256 checksum200 OK
GET/api/v1/files/{name}Download sample.txt, numbers.csv or logo.png200 OK, 404 Not found
POST/api/v1/filesUpload a file (multipart/form-data, a part named file, at most 1 MB). It is described and forgotten201 Created, 400 Bad request, 413 Body too big, 415 Unsupported media type
GET/api/v1/schemas/user.jsonJSON schema of one user200 OK
GET/api/v1/schemas/users-list.jsonJSON schema of a page of users200 OK
GET/api/v1/schemas/books.xsdXML schema (XSD) of /books.xml200 OK
GET/api/v1/secure/basicBasic authentication: user student, password Learn@123200 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/tokenOAuth 2 client credentials. Form fields: grant_type=client_credentials, client_id=lab-client, client_secret=lab-secret200 OK, 400 Bad request, 401 Unauthorized
GET/api/v1/secure/bearerNeeds the header Authorization: Bearer <token>200 OK, 401 Unauthorized
GET/api/v1/secure/apikeyNeeds the header X-API-Key: lab-key-123. Missing = 401, wrong = 403200 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 order204 No content, 400 Bad request, 404 Not found