
Imagine ordering food at a restaurant. You do not walk into the kitchen and cook it yourself. You choose from a menu, give your order, and wait for the kitchen to send the meal back.
An API is a similar way for two programs to talk. One program sends a request. Another program checks it and returns a response.
For example, a shop page may ask its server for product number 42. The server could reply:
{
"id": 42,
"name": "Blue mug",
"price": 12
}
The page can then show the name and price. It does not need direct access to the server’s database. The API provides a clear doorway with rules about what can be requested.
A website, a mobile app, and another service can use the same API. The server can also check permissions and return a useful error when something goes wrong.
Restaurant example: if the kitchen has run out of a dish, the waiter cannot bring it. In the same way, an API may reply that an item was not found or that the request is not allowed.
An API is not only for websites. It is a set of agreed rules that lets software exchange data safely and clearly.