Programming

API

What is API?

API means Application Programming Interface. In plain words, it is a ready way of talking. One side asks, the other side answers by the rule. You do not see the weather site's database. You send it an address, and it returns today's temperature as text or JSON. A map, a payment, and a translation are asked the same way. An API is not a language. It is not Python and it is not JavaScript. It is the path two programs agreed on. If the path changes, the answer to an old question can change too. That is why you look at the documentation.

What is API used for?

An API brings a ready job that lives somewhere else into your program. You do not write everything from zero.

  • Asking for the weather or a rate
  • Leaving a payment to another service
  • Giving the site's own data to a phone
  • Letting two programs talk without touching the same database

What can you do with API?

With an API you send a question and read the answer. Often the address is one path, and the method is GET or POST. GET is for reading. POST is for sending something new. The answer is often JSON: a key and a value. You show that text on your own page. An API does not draw the page and does not press the button. A door with a key is not open to everyone. If you write the key inside the page, a person who looks takes it. The key has to stay on the server.

Is API hard to learn?

Reading the weather from one open address is easy. The difficulty is the rule and the key. If the address changes by one letter, the old question breaks. There can be a limit: after a set number in a day the answer stops. The answer can be empty, wrong, or late. Do not put it on the page without checking. A question with someone else's key can take money or data. Do not start before reading what the document allows and what it forbids.

Advantages and limits

An API brings you a ready job and hides the inside. That is speed. The price is dependence. If the other side changes the address or closes the limit, your program stops too. If you write everything yourself, you depend less, but you write a lot. For a small site a ready API is a straight path. Never put the key where everyone can see it.

Basic ideas

An API is a door. The address is where the question goes. JSON is the written form of the answer.

  • A program asks a program, a person presses a button
  • GET reads, POST sends
  • The answer is often JSON
  • A key is not written on a page everyone sees

A short example

This is the simple form of an address for reading one user. The answer usually comes as JSON.

GET /users/12

{
  "id": 12,
  "name": "Nibras"
}

Common questions

  • Is an API a programming language? No. It is the talking rule of two programs. Python and JavaScript can be the languages that call it.
  • Are an API and a site the same? No. A person reads a site. A program reads an API. Both can come from the same data.
  • Can you write the key on the page? No. A person who looks takes it. The key has to stay on the server.