API’s & Integrations
What is an API?
An API, or Application Programming Interface, is a set of rules and protocols that allows different software applications to communicate and exchange data with each other. It acts as an intermediary, defining how one piece of software can request services or data from another, and how the other software will respond.
In simple terms, it’s like a messenger that takes requests from one application, tells another application what to do, and then brings back the response.
Example:
When you use a food delivery app:
- It sends a request to Google Maps (like “show restaurants near me”) and gets back the results in a usable format.
- The app uses Google Maps API to show your location.
Why Do We Need APIs?
We need APIs because they make modern software connected, efficient, and scalable. Without APIs, applications would work in isolation — unable to share data or use external services.
Here’s why APIs are essential:
1. Seamless Communication Between Systems
APIs act as a bridge between different applications, allowing them to talk to each other even if they’re built in different languages or platforms.
Example: A food delivery app uses APIs to communicate with restaurant systems, payment gateways, and map services.
2. Faster Development
Developers can reuse existing services instead of building everything from scratch.
Example: Instead of creating a login system, you can use Google or Facebook Login APIs.
3. Access to External Data and Services
APIs let you tap into external functionalities like payments, messaging, weather, or analytics.
Example: An e-commerce app uses Razorpay’s API for secure payments.
4. Scalability and Modularity
APIs make systems modular — meaning each part can evolve independently.
Example: You can upgrade your recommendation engine API without touching the entire product.
5. Ecosystem and Innovation
APIs help create platform ecosystems, enabling third-party developers to build new apps and integrations.
Example: Google Maps, Twitter, and Spotify APIs have spawned thousands of apps built around their data.
6. Automation
APIs allow different software systems to automate workflows without manual intervention.
Example: When a new order is placed, an API can automatically trigger invoice generation and shipment tracking.
Why are APIs important in product development?
APIs are crucial in product development because they make products more flexible, scalable, and faster to build. Here’s why they matter:
1. Enable Integration
APIs let your product connect easily with other tools, platforms, or services.
Example: A travel app can integrate flight data from an airline’s API, hotel info from a booking API, and maps from Google — all without building those systems from scratch.
2. Speed Up Development
Developers can reuse existing APIs instead of reinventing features.
Example: Use a payment API like Stripe instead of coding your own payment gateway.
3. Improve Scalability
As your product grows, APIs let you add or replace components without disrupting the whole system.
Example: You can switch from one analytics API to another with minimal changes.
4. Encourage Innovation
By exposing APIs, companies allow third-party developers to build on top of their products, creating new experiences.
Example: Instagram’s APIs let other apps schedule posts or analyze engagement.
5. Ensure Consistency and Security
APIs define clear communication rules, which makes data exchange reliable and secure across platforms.
How Do APIs Work?
APIs work as messengers that allow two systems to talk to each other — sending a request, processing it, and returning a response.
Here’s a step-by-step explanation.
🧩 1. The Client Makes a Request
A client (like a web app or mobile app) sends a request to the API.
The request includes:
- Endpoint (URL): Where it’s being sent
- Method: What action to perform (GET, POST, PUT, DELETE)
- Headers: Metadata like authentication tokens
- Body: Data to send (if required)
Example: A weather app requests data from
https://api.weather.com/v1/current?city=Delhi
⚙️ 2. The API Server Processes the Request
The API receives the request, checks the instructions, validates authentication, and then connects to a database or another service to gather or update information.
Example: The weather API checks its database for Delhi’s current temperature.
📦 3. The API Sends a Response
After processing, the API returns a response — usually in JSON format — with:
- Status code (e.g., 200 = success, 404 = not found, 500 = server error)
- Data payload (the actual information requested)
Example:
{
"city": "Delhi",
"temperature": "31°C",
"condition": "Sunny"
}
🔐 4. Security and Control
APIs use authentication (like API keys or OAuth tokens) to ensure only authorized users or apps can access the data.
🧠 Analogy:
Think of an API like a restaurant waiter:
- You (the client) order food (request).
- The waiter (API) tells the kitchen (server) what you want.
- The kitchen prepares the dish (data processing).
- The waiter brings it back to you (response).
What are the key aspects of an API?
Here are the key aspects of an API that define how it works and how developers interact with it:
1. Endpoints
These are the URLs or access points where requests are sent.
Example:
https://api.spotify.com/v1/tracks/{id}
Each endpoint performs a specific function — like fetching a song, posting data, or updating user info.
2. Methods (HTTP Verbs)
APIs use methods to tell what action to perform:
- GET → Retrieve data
- POST → Create new data
- PUT/PATCH → Update existing data
- DELETE → Remove data
3. Request and Response
Communication happens through requests and responses:
- A request includes method, endpoint, headers, and body (if needed).
- A response includes a status code (like 200 OK or 404 Not Found) and data — usually in JSON or XML format.
4. Authentication & Authorization
APIs often require secure access, using methods like:
- API keys
- OAuth tokens
- JWT (JSON Web Tokens)
This ensures only approved users or systems can use the API.
5. Rate Limiting
To prevent overuse, APIs set limits on how many requests you can make per minute or hour.
6. Documentation
Good APIs come with clear documentation explaining endpoints, parameters, examples, and error codes — essential for developers to use it effectively.
7. Versioning
APIs evolve over time, so versioning (like /v1/, /v2/) ensures older apps don’t break when updates are made.
What are the types of API architecture?
APIs can follow different architectural styles, which define how they are structured, how they communicate, and how data flows between systems.
Here are the main types of API architecture used in modern software development.
1. REST (Representational State Transfer)
- Most common and widely used API style.
- Uses HTTP methods (GET, POST, PUT, DELETE).
- Data is usually sent and received in JSON format.
- It’s stateless — each request is independent and doesn’t rely on previous ones.
Example:
GET https://api.github.com/users/sujith → fetches user data from GitHub.
Pros: Simple, scalable, cacheable
Used by: Twitter, GitHub, Google APIs
2. SOAP (Simple Object Access Protocol)
- An older, XML-based protocol that’s very strict and standardized.
- Often used in enterprise and financial systems where strong security and reliability are key.
Used by banking systems, legacy healthcare APIs (HL7), etc.
Pros: High security, strong contracts
Cons: Complex, heavy payloads
3. GraphQL
- A query-based API architecture developed by Facebook.
- The client can request exactly the data it needs, nothing more or less.
- Uses a single endpoint for all operations.
Example:
{ user(id: "123") { name posts { title } } }
Pros: Efficient, flexible, reduces over-fetching
Used by: GitHub, Shopify, Netflix
4. gRPC (Google Remote Procedure Call)
- Uses Protocol Buffers (Protobuf) instead of JSON for faster, smaller data exchange.
- Ideal for microservices communication within distributed systems.
Pros: High performance, low latency
Used by: Google, Square, and internal microservice systems
5. WebSockets
- Enables real-time, two-way communication between client and server.
- Common in chat apps, live dashboards, or gaming.
Pros: Real-time updates, persistent connection
Used by: WhatsApp Web, Slack, trading platforms
6. RESTful vs. Non-RESTful APIs
Non-RESTful: May use hybrid or custom communication patterns.
RESTful: Follows REST principles strictly.
What is a REST API? How does it differ from SOAP?
A REST API (Representational State Transfer API) is a style of web service that allows systems to communicate over the internet using standard HTTP methods — GET, POST, PUT, DELETE, etc. It’s based on simple, stateless communication and usually exchanges data in JSON format.
Here’s a breakdown:
Resources & Endpoints: Everything (like users, products, orders) is treated as a resource accessed via unique URLs.
Architecture style: REST is not a protocol but a set of design principles.
Data format: Typically uses JSON (sometimes XML).
Stateless: Each request contains all the information needed; the server doesn’t store client context.
Example:
GET https://api.example.com/users/123
This might return details of the user with ID 123.
What is SOAP?
SOAP (Simple Object Access Protocol) is a protocol designed for exchanging structured information in web services using XML.
It defines strict rules for message structure, error handling, and communication between systems. SOAP messages are wrapped in an XML envelope that defines:
- Header: For authentication, routing, etc.
- Body: The actual request or response data.
Example (SOAP Request):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUserDetails xmlns="http://example.com/users">
<UserId>123</UserId>
</GetUserDetails>
</soap:Body>
</soap:Envelope>
Key Features:
- Protocol-based: Has strict standards for communication.
- XML only: Every request and response is XML.
- Built-in error handling: Uses
<Fault>elements in responses. - High security & reliability: Supports WS-Security, ACID transactions, etc.
- Transport flexibility: Can use HTTP, SMTP, TCP, etc.
SOAP is often used in enterprise systems where reliability and security are critical — like banking, healthcare, or government integrations.
REST vs SOAP: Quick Comparison
| Feature | REST | SOAP |
|---|---|---|
| Type | Architectural style | Protocol |
| Data Format | JSON, XML, or others | XML only |
| Transport | HTTP (mainly) | HTTP, SMTP, TCP, etc. |
| Complexity | Simple, lightweight | Complex, rigid |
| Performance | Faster, smaller payloads | Slower, heavy XML |
| Security | Relies on HTTPS | Built-in WS-Security |
| Use Cases | Web/mobile apps, microservices | Enterprise apps, financial transactions |
What is an endpoint?
An endpoint is the specific URL or address where an API can be accessed by a client to perform an action or retrieve data.
Think of it as the doorway to a specific resource or function in an API.
In simple terms:
If an API is like a restaurant,
- The menu = API documentation (shows what you can order)
- The kitchen = Server (where the logic happens)
- The endpoints = The counters (specific places you go to request each dish)
🔹 Example (REST API)
Let’s say you have an API for a shopping app:
Base URL: https://api.shop.com
Then, you can have different endpoints for various resources:
| Purpose | HTTP Method | Endpoint | Description |
|---|---|---|---|
| Get all products | GET | /products | Returns a list of all products |
| Get one product | GET | /products/25 | Returns details of product ID 25 |
| Add a product | POST | /products | Adds a new product |
| Update a product | PUT | /products/25 | Updates product ID 25 |
| Delete a product | DELETE | /products/25 | Deletes product ID 25 |
Each of these URLs (/products, /products/25, etc.) is an endpoint — a point where the client and server communicate.
What are common methods used in REST APIs
In REST APIs, the communication with resources is done using standard HTTP methods. The most common ones are:
1. GET
- Purpose: Retrieve data from the server.
- Characteristics:
- Safe: Doesn’t modify data.
- Idempotent: Calling it multiple times has the same effect.
- Example:
GET https://api.shop.com/products/25
This fetches the details of product ID 25.
2. POST
- Purpose: Create a new resource on the server.
- Characteristics:
- Not idempotent: Calling it multiple times may create multiple resources.
- Example:
POST https://api.shop.com/products
Request Body (JSON):
{
"name": "Wireless Mouse",
"price": 25.99
}
This creates a new product with the given details.
3. PUT
- Purpose: Update an existing resource completely.
- Characteristics:
- Idempotent: Sending the same request multiple times produces the same result.
- Example:
PUT https://api.shop.com/products/25
Request Body (JSON):
{
"name": "Wireless Mouse Pro",
"price": 29.99
}
This replaces the entire product record with new data.
4. PATCH
- Purpose: Partially update an existing resource.
- Characteristics:
- Idempotent: Reapplying the same patch yields the same result.
- Example:
PATCH https://api.shop.com/products/25
Request Body (JSON):
{
"price": 27.99
}
This updates only the price of product ID 25.
5. DELETE
- Purpose: Remove a resource from the server.
- Characteristics:
- Idempotent: Deleting the same resource multiple times has the same effect (after first deletion, resource no longer exists).
- Example:
DELETE https://api.shop.com/products/25
This deletes product ID 25.
Quick Summary Table
| Method | Purpose | Idempotent? |
|---|---|---|
| GET | Retrieve data | Yes |
| POST | Create new data | No |
| PUT | Replace existing data | Yes |
| PATCH | Update part of existing data | Yes |
| DELETE | Delete data | Yes |
What is a loadbalancer? And why do we need one?
A load balancer is a system or device that distributes incoming network traffic across multiple servers to ensure no single server gets overwhelmed.
Think of it like a traffic cop directing cars (user requests) to different lanes (servers) so that the flow stays smooth and fast.
Why We Need a Load Balancer
When an application or API gets thousands (or millions) of requests per second, a single server can’t handle it all.
A load balancer helps by:
- Improving performance (faster response times)
- Increasing reliability and uptime (if one server fails, others handle the traffic)
- Enabling scalability (you can add or remove servers easily)
How It Works
- A client sends a request to the app (e.g.,
https://api.example.com).
- The load balancer receives that request first.
- It then forwards the request to one of several backend servers based on a distribution rule.
- The chosen server processes the request and sends the response back to the load balancer, which forwards it to the client.
What are the different types of load balancers, and how do they differ in terms of deployment and functionality?
A load balancer can be implemented in several ways depending on the infrastructure and business needs. The main types are:
a) Hardware Load Balancer
- A physical device placed between clients and servers.
- Performs traffic distribution using specialized hardware.
- Often used in enterprise data centers where high performance and low latency are critical.
- Example: F5 Networks BIG-IP, Citrix ADC.
- Pros: Very fast, reliable, and secure.
- Cons: Expensive, less flexible to scale.
b) Software Load Balancer
- Installed as software on a general-purpose server or container.
- Uses configurable algorithms to route traffic.
- Common in modern cloud-native or on-prem setups.
- Example: Nginx, HAProxy, Traefik.
- Pros: Flexible, cost-effective, easily automated.
- Cons: May require more setup and tuning.
c) Cloud (Managed) Load Balancer
- Offered as a managed service by cloud providers.
- Handles scaling, health checks, and routing automatically.
- Ideal for dynamic, large-scale applications.
- Example: AWS Elastic Load Balancer (ELB), Azure Load Balancer, Google Cloud Load Balancer.
- Pros: Auto-scaling, easy setup, pay-as-you-go.
- Cons: Less control over low-level configurations.
Summary:
| Type | Description | Examples | Best For |
|---|---|---|---|
| Hardware | Dedicated physical device | F5, Citrix | Enterprise, low-latency apps |
| Software | Runs on general-purpose servers | Nginx, HAProxy | Cloud/on-prem apps |
| Cloud | Managed by cloud providers | AWS ELB, Azure LB | Scalable web services |
What are the common load balancing algorithms used, and how does each one decide which server should handle a request?
Load balancers use algorithms to decide how to distribute incoming requests across servers. The choice of algorithm affects performance, efficiency, and fairness.
a) Round Robin
- Sends each new request to the next server in a sequence.
- Loops back to the first server after reaching the last.
- Best for: Environments where all servers have equal capacity.
- Example:
Request 1 → Server A
Request 2 → Server B
Request 3 → Server C
Request 4 → Server A
b) Least Connections
- Routes the request to the server with the fewest active connections.
- Best for: Systems where requests take different processing times.
- Example: Ideal for APIs or dynamic workloads.
c) Weighted Round Robin
- Similar to Round Robin but assigns weights to servers based on capacity.
- More powerful servers get more requests.
- Best for: Mixed environments (some servers stronger than others).
d) IP Hash
- Uses a hash of the client’s IP address to decide which server handles the request.
- Ensures that the same client is routed to the same server (session persistence).
- Best for: Applications needing consistent sessions (e.g., shopping carts).
e) Random
- Routes each new request to a randomly selected server.
- Best for: Simple, evenly balanced clusters with light traffic.
Summary:
| Algorithm | Logic | Best Use Case |
|---|---|---|
| Round Robin | Sequential rotation | Equal-capacity servers |
| Least Connections | Fewest current users | Uneven request loads |
| Weighted Round Robin | Based on server capacity | Mixed-power servers |
| IP Hash | Based on client IP | Session persistence |
| Random | Random selection | Light, evenly distributed traffic |
