
Almost every app you use talks to other services behind the scenes. A weather app asks a forecast service for today's temperature, a shop asks a payment provider to charge a card, and a map shows places supplied by another company. They do this through APIs, application programming interfaces: agreed ways for one program to ask another for data or actions. Learning to use them lets even small projects work with real data.
Think of an API as a restaurant menu. You do not need to know how the kitchen works, only what you can order and how. Most web APIs today follow the REST style, described by computer scientist Roy Fielding in his 2000 doctoral dissertation. A REST API exposes resources, such as users, products or forecasts, at web addresses and uses the ordinary rules of HTTP, the same protocol your browser uses to load pages.
Every API call is a request from your program and a response from the server. A request has these parts:
The response contains a status code, headers and usually a body with the data you asked for.
JSON, short for JavaScript Object Notation, is the most common format for API data. It is plain text built from two structures: objects, which are key-value pairs inside curly braces, and arrays, which are ordered lists inside square brackets. A weather response might look like {"city": "Paris", "temp": 18, "tags": ["sunny", "dry"]}. Keys are always in double quotes, and values can be text, numbers, true, false, null, objects or arrays. Every modern language can convert JSON, so you can read data["temp"] in Python or data.temp in JavaScript.
Good APIs come with documentation that lists the endpoints, required parameters, example responses, authentication rules and limits. Read the getting-started page and look for a test mode. Many providers also offer interactive pages where you can try requests in the browser. Start with a free, simple API before working with anything that involves payments or personal data.
A GET request to a public endpoint can be opened directly in your browser. For more control, use one of these tools:
Most APIs need to know who is calling. The simplest method is an API key, a long secret string you get from the provider's dashboard and send with each request, often in a header such as Authorization: Bearer YOUR_KEY or X-API-Key. Treat any key like a password:
Always check the status code before using the data. Codes in the 200s mean success, 400 means your request was malformed, 401 or 403 point to missing or invalid credentials, 404 means the resource does not exist, 429 means you sent too many requests, and codes in the 500s are server problems. Most APIs set rate limits, such as 60 requests per minute. Respect them: cache results you reuse, wait before retrying and set a timeout so your program does not hang when a server is slow.
Pick one free API that interests you, such as weather or books, and build something small: a script that prints a daily forecast or a page that lists search results. Once you are comfortable consuming APIs, try building a REST API with Node.js yourself. Seeing both sides makes every new API easier to understand.
Grade 10 Math: Functions and Reasoning - Quiz
1170 questions