# What Is an API?

In today’s digital world, apps and websites often **talk to each other**. This communication happens through something called an **API** — short for **Application Programming Interface**.

### What Does an API Do?

An API is like a **messenger**.

* It **sends your request** to another system.
    
* It **brings back the answer** so your app can show it.
    

Imagine you open a food delivery app and want to see pizza shops nearby.

* Your app sends a request through an API to a server.
    
* The server sends back a list of shops.
    
* The app shows it to you.
    

## How Does an API Work?

You (the user or app) **send a request** → “Give me data!”  
The API **takes the request** → Goes to the server.  
The server **processes it** → Finds the data.  
The API **returns the result** → App displays it.

### Common API Terms

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Request</strong></p></td><td colspan="1" rowspan="1"><p>The data your app sends to the API</p></td></tr></tbody></table>

<table><tbody><tr><td colspan="1" rowspan="1" colwidth="400"><p><strong>Response</strong></p></td><td colspan="1" rowspan="1"><p>The data the API sends back</p></td></tr></tbody></table>

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Endpoint</strong></p></td><td colspan="1" rowspan="1"><p>The specific URL where the API listens</p></td></tr></tbody></table>

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>JSON</strong></p></td><td colspan="1" rowspan="1"><p>A common format for API data (looks like <code>{ "name": "Nepal" }</code>)</p></td></tr></tbody></table>

## Why do we need the API

Imagine you’re building a food delivery app.

* You want to **show the user’s location on a map**.
    
* You want to **find nearby pizza shops**.
    
* You want to **draw the delivery route**.
    

Could you build your own map system?  
That would take years, cost millions, and need constant updates.

Instead, you use **Google Maps API**

* Your app asks Google Maps: *“Where is this address?”*
    
* Google Maps API responds with the location, shops, route, etc.
    
* Your app shows the map, markers, and route — easy!
    

This is one example of API call:

```plaintext
GET https://api.weather.com/v3/weather/forecast?location=Kathmandu
```

This is how it’s response can look which we use as how we want to use in our case:

```plaintext
{
  "location": "Kathmandu",
  "forecasts": [
    {
      "day": "Monday",
      "high_temp_c": 28,
      "low_temp_c": 18,
      "description": "Partly cloudy"
    }
  ]
}
```

Moreover, An API is secured by using **API keys** so only authorized apps can access it. To prevent overuse, **throttling (rate limiting)** controls how many requests are allowed in a time period, like 100 requests per minute. Common throttling methods include **fixed window** and **token bucket**.

*This keeps the API safe, reliable, and fair.*
