An API, or Application Programming Interface, is a set of rules that lets software systems communicate with each other. It matters because modern apps rarely work alone. A weather app, payment page, login button, or map view often depends on APIs to request data or services from another system.
APIs make software modular, reusable, and easier to connect across devices and platforms.
A typical API interaction starts when a client sends a request to an endpoint, such as asking a server for a user profile or a list of products. The server checks the request, runs the needed logic, and sends back a response containing data, a status code, or an error message. Many web APIs use HTTP methods like GET, POST, PUT, and DELETE to describe the action being requested.
Good API design uses clear endpoints, predictable data formats, authentication, and error handling so different systems can work together reliably.
Understanding API Basics
REST treats information as resources. A resource can be a student record, a photo, a bus route, or a game score. Good endpoint names usually describe these resources with nouns rather than actions.
One endpoint may represent a collection of books, while another represents one book chosen by its identifier. This structure helps programmers predict where data belongs. A well designed API keeps related resources organised in a consistent way.
It separates the data service from the screen a person sees. The same service can then support a website, a phone app, and a school dashboard without each one needing its own copy of the data.
Requests carry more context than the endpoint alone. Headers can state the data format, the preferred language, or a security credential. The body of a request often contains structured data in JSON, which stores information as named values.
Before saving that data, a server should check its type, required fields, length, and allowed values. For example, an age field should not accept a paragraph of text. Authentication proves who is making the request.
Authorisation decides what that person is allowed to do. A student may read their own marks, while a teacher may enter marks for a class. Secure systems keep passwords and secret keys out of public code and logs.
Network communication is not always reliable. A request can be delayed, interrupted, sent twice, or reach a server that is temporarily overloaded. This is why clients need clear handling for failed responses.
A temporary failure may justify waiting briefly before trying again. Repeating a request that creates an order can be dangerous if it makes two orders. Some operations are designed to be idempotent, meaning that repeating the same request leaves the final result unchanged.
Large lists create another practical issue. An API may return results in pages rather than sending thousands of records at once.
Caching can save a recent response for a short time, reducing delay and server work. Rate limits protect a service when too many requests arrive from one source.
Students meet APIs whenever an app loads a timetable, shows delivery tracking, signs in with an account, or displays live sports results. In a browser, developer tools can show the requests made as a page loads. This makes invisible communication easier to inspect.
Look at the requested path, method, response code, and returned JSON. API documentation is important because it defines field names, required inputs, limits, and examples. Small differences matter.
A missing field, an expired token, or a wrongly spelled endpoint can stop a program. When learning, practise reading responses carefully and treating error messages as evidence about what the server expected. Good API work depends on accuracy, security, and clear agreements between people building different parts of a system.
Key Facts
- API = Application Programming Interface, a contract for how software components exchange requests and responses.
- Request = method + endpoint + headers + optional body.
- Response = status code + headers + optional body.
- GET retrieves data, POST creates or submits data, PUT updates data, and DELETE removes data.
- Latency = response received time - request sent time.
- Common HTTP status codes include 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, and 500 Server Error.
Vocabulary
- API
- An API is a defined way for one software system to request data or actions from another software system.
- Endpoint
- An endpoint is a specific URL or address where an API can receive a request.
- HTTP Method
- An HTTP method is a command such as GET, POST, PUT, or DELETE that tells the server what kind of action the client wants.
- JSON
- JSON is a common text format for sending structured data between a client and a server.
- Authentication
- Authentication is the process of proving that a user or program is allowed to access an API.
Common Mistakes to Avoid
- Using GET to change server data is wrong because GET should normally be safe and used for retrieval, not creation, updates, or deletion.
- Ignoring status codes is wrong because the response body alone may not clearly show whether the request succeeded, failed, or needs authentication.
- Sending private API keys in public client-side code is wrong because anyone can inspect the app and steal the key.
- Assuming every API returns the same data shape is wrong because endpoints can have different schemas, optional fields, and error formats.
Practice Questions
- 1 A client sends a request at 12:00:00.250 and receives the response at 12:00:00.890. What is the API latency in milliseconds?
- 2 An app makes 1,200 API requests in 10 minutes. What is the average number of requests per minute, and what is the average number of requests per second?
- 3 A shopping app needs to show a product list, add a new review, update a shipping address, and remove an item from a cart. Choose the most appropriate HTTP method for each action and explain your reasoning.