ASHU
Backend

API — Explained Simply

8 min read

What is an API?

API (Application Programming Interface) is a messenger that lets two software systems talk to each other.

👉 One app requests data or action 👉 Another app responds with data or result


Simple Real-Life Example 🍽️

Restaurant analogy:

  • You = Client
  • Kitchen = Server
  • Waiter = API

You don't go into the kitchen. You tell the waiter what you want. The waiter brings the food.

That waiter is the API.


Why APIs are used?

APIs help to:

  • Share data between systems
  • Keep systems secure
  • Avoid direct database access
  • Reuse functionality
  • Build scalable applications

How an API Works (Basic Flow)

  1. Client sends a request
  2. API receives the request
  3. Server processes it
  4. API sends a response
Client → API → Server → API → Client

API Request Contains

  • URL (Endpoint) – where to send request
  • Method – what action to perform
  • Headers – extra info (auth, format)
  • Body – data (optional)

Example:

GET /users/1

API Response Contains

  • Status code (success / error)
  • Data (usually JSON)
  • Message

Example:

{
  "id": 1,
  "name": "Ashutosh"
}

Common HTTP Methods

MethodMeaning
GETRead data
POSTCreate data
PUTUpdate entire data
PATCHUpdate partial data
DELETERemove data

HTTP Status Codes (Must Know)

CodeMeaning
200Success
201Created
400Bad request
401Unauthorized
403Forbidden
404Not found
500Server error

Types of APIs

1️⃣ REST API (Most common)

  • Uses HTTP
  • Stateless
  • Uses JSON
  • Easy to use

2️⃣ GraphQL

  • Client asks for exact data
  • Single endpoint
  • Flexible but complex

3️⃣ SOAP

  • XML based
  • Very strict
  • Used in old enterprise systems

4️⃣ Internal API

  • Used inside same company

5️⃣ Public API

  • Available for everyone (Google Maps, OpenAI)

REST API Principles (Easy)

  • Uses HTTP methods
  • Uses clear URLs
  • Stateless (no memory)
  • Resource-based

Example:

GET /users
POST /users
GET /users/5

API Authentication

Used to protect APIs.

Common types:

  • API Key
  • Bearer Token (JWT)
  • OAuth
  • Basic Auth

Example:

Authorization: Bearer <token>

API Security Basics

  • Authentication
  • Authorization
  • Rate limiting
  • HTTPS
  • Input validation

API Formats

Most common:

  • JSON ✅ Others:
  • XML
  • Form data

API Testing Tools

  • Postman
  • Thunder Client
  • Curl

API Versioning

Used when API changes.

Examples:

/api/v1/users
/api/v2/users

API vs Backend

APIBackend
InterfaceLogic + Database
Communication layerProcessing layer
Sends/receives dataStores & computes data

API vs Webhook

APIWebhook
Client requestsServer pushes
Pull-basedPush-based
On demandEvent-based

Real-World API Examples

  • Login / Signup
  • Payment (Stripe)
  • Maps (Google Maps)
  • AI (ChatGPT API)
  • Weather apps
  • Social media feeds

One-Line Summary (Remember This)

API is a bridge that lets different software systems communicate safely and efficiently.