Intermediate level · Module 4: Working with Web APIs · Lesson 1 of 3
How Web APIs Work
Understand requests, responses, URLs, query parameters and status codes before writing client code.
In this lesson you will
- Read API documentation
- Interpret status codes such as 200, 400, 401, 404 and 500
Key concepts
endpointGET/POSTstatus codeAPI key
The lesson
A web API lets one program request data or services from another over the internet. Your program sends an HTTP request to a URL (the endpoint) and receives a response, usually in JSON.
The response includes a status code: 200 means success, 404 not found, 401 or 403 means you are not authorised, 429 means too many requests and 500-level codes mean the server failed. Your code should check the status before using the data.
API documentation tells you the endpoint, the parameters (such as a city or currency code), whether you need an API key, and the structure of the response. Reading documentation carefully is most of the work.
Step by step
- Open a public API's documentation.
- Find the endpoint and required parameters for one request.
- Open the request URL in a browser and read the JSON response.
- Write down the fields your program will use.
Practice activity
Using a public API's documentation, identify the endpoint, parameters and response fields needed to get a weather forecast for Juba.
Expected result: A written request plan listing endpoint, parameters and the fields to use.
Check your understanding
-
What does status code 404 mean?
Show answer
The requested resource was not found.
-
Why should API keys never be committed to GitHub?
Show answer
Anyone who sees the repository could use the key, causing misuse or charges.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.