Tutorial

What is an API?

Every app you love is really two apps: the face you tap and the brain that holds the data. An API is how they talk to each other.

The restaurant version

You never walk into the kitchen. You read the menu, tell the waiter your order, and the food arrives. An API works the same way:

  • The menu is the API documentation: it lists what's available and how to ask.
  • Your order is the request: a URL, a method, and sometimes data.
  • The food is the response: the data you asked for, usually as JSON.

API stands for Application Programming Interface: the agreed way for software to ask another piece of software for things.

Anatomy of a request

When your weather app shows today's forecast, it sent something like this:

GET https://api.example.com/weather?city=Lahore
Header: Authorization: Bearer YOUR_KEY

Four parts: the method (what kind of action), the endpoint (the URL being asked), optional parameters (like ?city=Lahore), and headers (metadata, often including your API key).

The four verbs

Most APIs use these HTTP methods, matching the CRUD pattern:

MethodDoesExample
GETReads dataGET /users lists users
POSTCreates dataPOST /users adds a user
PUT / PATCHUpdates dataPUT /users/5 edits user 5
DELETERemoves dataDELETE /users/5 deletes user 5

What comes back

The server answers with a status code (200 means success, 404 means not found, 500 means the server messed up) and the data, usually in JSON:

{
  "city": "Lahore",
  "temp_c": 31,
  "condition": "Sunny"
}

JSON is just a way to write structured data that both humans and machines can read. Your app turns this into the pretty screen you see.

How to read any API docs

Documentation looks intimidating until you know it only ever answers five questions:

  1. Base URL: where do requests go?
  2. Endpoints: what URLs exist, and what does each return?
  3. Methods: GET, POST, or something else per endpoint?
  4. Authentication: do you need a key, and where does it go?
  5. Errors: what do the status codes mean for this API?

Answer those five and you can use any API. The honest caveat: APIs have rate limits and terms of use. Read them before building something that depends on someone else's server.

A complete request and response, step by step

A weather widget on a phone home screen gives a clear picture of a full exchange. The widget needs current conditions for one city. It sends a request to a weather service and waits for data it can place on screen.

The request looks like this in plain text:

GET /v1/weather?city=Karachi HTTP/1.1
Host: api.weather.example
Authorization: Bearer abc123examplekey
Accept: application/json

The first line holds the method, the path, and the HTTP version. GET means the widget wants to read data. The path /v1/weather names the endpoint. The query string ?city=Karachi narrows the request to one city. HTTP/1.1 is the version of the protocol both sides speak.

The lines after the first line are headers. Host names the server that should answer. Authorization carries the API key so the service can identify the app making the call. Accept tells the server the widget wants the answer as JSON. A browser sends similar headers on every page load, including language and device details.

The service checks the key, looks up Karachi in its data, and sends a response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "city": "Karachi",
  "temp_c": 34,
  "humidity": 62,
  "condition": "Partly cloudy",
  "wind_kph": 18
}

The first line of the response gives the status. 200 OK means the request worked. Content-Type confirms the body is JSON. A blank line separates the headers from the body. The body holds the fields the widget needs. The widget reads temp_c and condition and paints them into the small card on the home screen. If the city name were misspelled, the service might return 404 with a short error message in JSON instead, and the widget would show a fallback message to the user.

API keys and what happens when one leaks

An API key is a long string that identifies an app or a developer account to a service. The service uses it to decide who is calling, to enforce rate limits, and to track usage for billing when a plan has paid tiers. Some keys only read public data. Other keys can write or delete data, and those need stricter handling.

On a web project, the key belongs on the server. Your server side code reads the key from an environment variable or a config file outside the public web folder and adds it to outgoing requests. Code that runs in the browser is visible to anyone who opens developer tools, so a key placed in frontend JavaScript is public as soon as the page loads. Mobile apps have a similar problem because anyone can inspect the app package. For browser and mobile calls, use a small server endpoint as a go between, or use a restricted key that the provider limits to one domain or one app identifier.

When a key leaks, anyone who finds it can call the API as if they were you. Common leak points include public code repositories, screenshots in bug reports, and log files shared for support. The calls count against your quota. If the key allows writes, a stranger could change or delete data. The fix is to revoke the old key in the provider dashboard right away and issue a new one, then update the server config. Rotation alone does little if the new key goes in the same public place, so move it to server side storage before you switch it on.

Frequently asked questions

What does REST mean?

Representational State Transfer: a set of conventions for building APIs over HTTP. Each request is independent (stateless), and standard methods do standard things. Most web APIs you'll meet are REST.

Is an API the same as a website?

Same technology, different audience. A website returns pages for humans; an API returns data for software.

Do I need to know a backend language to use APIs?

No. Consuming an API, making requests and reading JSON, is a frontend skill. Building one is where backend languages come in.

Last verified: October 25, 2026, against MDN Web Docs. REST conventions and HTTP methods are stable standards.

Need an API built or integrated?

We build and connect APIs: payment gateways, maps, CRMs, and custom backends.

Get a quote →

← All tutorials