What is an API?
An API, or Application Programming Interface, is a set of rules that lets one piece of software ask another piece of software to do something, or share data. You do not need to know how the other system works inside. You only need to know how to ask.
Think of a waiter in a restaurant. You do not walk into the kitchen. You tell the waiter what you want, the waiter passes the order to the kitchen, and then brings your food back. The API is the waiter between you and the kitchen.
How an API works
Most web APIs follow a simple request and response pattern:
- A client sends a request to an API endpoint, which is a specific URL.
- The server checks the request, including who is asking and whether they are allowed.
- The server does the work, such as reading from a database.
- The server sends back a response, usually as data in JSON format, along with a status code.
This happens over HTTP, the same protocol your browser uses. The server handling these requests is often a web server with an application running behind it.
A simple example
Here is a request to a weather API:
GET https://api.example.com/weather?city=Mumbai
And the response:
| { “city”: “Mumbai”, “temperature”: 31, “condition”: “Partly cloudy”} |
Your app asked for the weather. The API returned the data. Your app then shows it to the user.
Common HTTP methods
| Method | What it does |
| GET | Reads data |
| POST | Creates new data |
| PUT / PATCH | Updates existing data |
| DELETE | Removes data |
Common status codes
- 200: Success
- 201: Created
- 400: Bad request, something was wrong with what you sent
- 401 / 403: Not authenticated, or not allowed
- 404: Not found
- 429: Too many requests
- 500: Server error
Types of APIs
- REST: The most common style. Uses standard HTTP methods and URLs, and usually returns JSON. Simple and widely supported.
- GraphQL: Lets the client ask for exactly the data it needs in one request, instead of many.
- SOAP: An older, stricter, XML-based style, still used in some enterprise and banking systems.
- gRPC: A fast, compact style often used for communication between internal services.
- WebSocket: Keeps a connection open for real-time updates, like chat or live prices.
REST vs GraphQL
| REST | GraphQL | |
| Structure | Many endpoints, one per resource | One endpoint, flexible queries |
| Data returned | Fixed by the endpoint | Only what the client asks for |
| Best for | Simple, standard, cacheable APIs | Complex apps with varied data needs |
Public, private, and partner APIs
- Public (open) APIs: Available to any developer, often with an API key.
- Private (internal) APIs: Used only inside a company to connect its own systems.
- Partner APIs: Shared with specific business partners under an agreement.
API authentication
Most APIs need to know who is calling. Common methods include:
- API keys: A unique string sent with each request.
- OAuth tokens: Let a user grant limited access without sharing a password.
- JWT (JSON Web Tokens): Signed tokens that prove identity.
Always send API requests over HTTPS and never put keys in public code.
Rate limiting
Many APIs limit how many requests you can make in a set time, for example 100 per minute. This protects the service from overload and abuse, including traffic floods like a DDoS attack. If you go over the limit, you usually get a 429 error and need to wait.
Why APIs matter
- Reuse: Developers use existing services instead of building everything from scratch.
- Integration: Different apps and systems can share data.
- Automation: Tasks that once needed manual clicks can run from code.
- Scale: Teams can build and update parts of a product independently.
APIs in cloud computing
In the cloud, nearly everything you can do in a dashboard can also be done through an API. You can create servers, attach storage, change firewall rules, and scale resources with code. This is how automation tools and infrastructure as code work. It is also why cloud computing is so flexible.
Kubernetes works the same way. Every action goes through its API, handled by kube-apiserver.
Where API performance matters
API speed depends on server performance and distance to the user. A server far away adds latency, and a heavy load can slow responses. Teams often spread API traffic across servers with load balancing and run services in containers so they scale easily.
If your team wants to automate infrastructure, an API-first cloud makes it much easier. CloudPe lets you manage cloud resources through an API, so you can create, scale, and control your servers with code, on India-based infrastructure.