API stands for Application Programming Interface. It defines the requests a program may send to another program, the information each request must include, and the form of the answer it will receive. An API lets software parts work together without needing to see each other's internal code.
A request usually names an endpoint, which is a web address for one resource, and a method that says what to do. Common methods are GET to read data, POST to create data, PUT or PATCH to change data, and DELETE to remove data.
The response includes a status code and often a body with data. A status code 200 means success, 404 means the requested resource was not found, and 500 means the server had an internal error. Many APIs send the body in JSON, a plain text format that stores named fields.
Inside your account
What an account adds to the pages you are reading.
Lessons
Topic explanations with worked examples, split into units.
An API works like a contract: it lists what can be requested and what will be returned.
An endpoint is a specific address for one resource, such as the list of lessons.
GET reads data without changing it; POST creates new data.
Status codes in the 2xx range mean success, 4xx mean the request had a problem, and 5xx mean the server had a problem.
API keys identify the caller and must be kept secret.
Example
A weather app wants the temperature for one city. It sends a GET request to the weather service's endpoint for that city. If the city exists, the service returns status 200 and a JSON body with a field such as 'temperature': 21. If the city name is wrong, the service returns 404.
Question: a service allows 100 requests per minute, and an app has already made 60 in the current minute. How many more requests can it make? 100 minus 60 leaves 40 more requests.
Common mistakes
Thinking an API is the same as a website. A website shows pages to people; an API returns data to programs.
Putting a secret API key in public code. Anyone who can read the code can use the key.
Ignoring status codes. A program should check the status before it uses the body.
Sending requests in a loop with no limit. Many services restrict how many requests are allowed.
Summary
An API defines how one program requests data or actions from another. Requests use endpoints and methods, responses carry status codes and data, and secret keys must stay private. Knowing these parts makes it easier to read and debug any API.
Frequently asked questions
Is an API the same as a library?
Not exactly. A library is code that runs inside your program. An API is a set of rules for asking another program for something, often over a network.
What is JSON?
JSON is a plain text format that stores data as pairs of names and values, such as 'temperature' and 21. Many APIs use it for responses because both people and programs can read it.
Why must an API key stay secret?
A key identifies who is making requests, and a service may limit or charge usage based on it. If someone else gets the key, they can use the account's permissions and quota.