REST APIs: using and building them
You explore a REST API with curl and small scripts, read and change resources, then write and document your own simple API.
Level 201 · 18 lessons · 15 practice labs
Lessons
Using an API
- What an API is: a contract for programs to talk
- Resources, URLs and methods
- Reading a JSON API with curl and jq
- Query parameters: filtering, sorting, paging
- Creating, updating and deleting records
- Reading error responses
- Requests with an API key or token
- Short task: explore an undocumented API
Writing a client
- An API client in Python
- An API client with JavaScript fetch
- Walking through every page
- Rate limits and retries
- Short task: a script that exports CSV from an API
Building an API
- Your first API server
- Input validation and meaningful errors
- Storing data in SQLite
- Documenting with OpenAPI
- Capstone: an inventory API
Practice labs
- Pull one field out of an API response: List only the in-stock book titles from the lab's book API with curl and jq.
- Narrow results with query parameters: Use filter, sort and page parameters on the product API to fetch a category's second five most expensive products.
- Classify error responses: Send deliberately bad requests to an API and explain why each 400, 401, 404, 409 and 422 came back.
- Create, update and delete a task: Create a task in the task API with curl, change its status with PATCH and then delete it.
- Send a token-protected request properly: Fix a request returning 401 with an Authorization header and use the token without leaving it in shell history.
- Show PUT versus PATCH in the data: Update a customer record with a partial body via PUT and then PATCH and compare which fields got wiped.
- Fetch the branch list with Python: Fetch the branch API's city list with requests and print it as a tidy table.
- Walk every page via the link header: Write a client that walks every page of a customer API returning 20 records per page by following the Link header.
- Make a JavaScript client respect rate limits: Make a fetch-based client honour Retry-After on 429 responses, retry, and report the total time taken.
- Add a health-check endpoint: Add a /health endpoint that returns version and uptime to an existing small API.
- Return per-field errors for bad input: Produce 422 responses with per-field messages for missing and invalid fields in an event-signup API.
- Back an appointment API with SQLite: Move an appointment API that keeps data in memory to SQLite and rewrite CRUD with parameterised queries.
- Document an endpoint in OpenAPI: Write a product-listing endpoint's parameters and responses into an OpenAPI file.
- Find where the docs and behaviour differ: Compare what the OpenAPI document says with what the API actually returns, then find and fix three mismatches.
- Generate a client from the spec and try it: Generate a client from an OpenAPI document, run it against the stock API and fix the error caused by a missing schema.
About this course
You explore a REST API with curl and small scripts, read and change resources, then write and document your own simple API.
What you will learn
- Using an API
- Writing a client
- Building an API
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.