APIs & JSON
Learn requests, responses, errors, and structured data.
A request asks for a resource
An HTTP request has a method and URL, and may include headers and a body. A response has a status code and usually some data.
Check status before parsing
A response body is not always successful application data. Handle unsuccessful HTTP status codes, empty bodies, network errors, and JSON errors separately.
JSON represents structured values
JSON uses objects, arrays, strings, numbers, booleans, and null. Keys and strings use double quotes.
{
"city": "Example City",
"temperature": 24.5,
"available": true
}Try it yourself
For a weather screen, list what the UI should show while loading, on success, for an unknown city, and when the device is offline.


