The client sends a request
A web page, mobile app or another server sends an HTTP request to an endpoint, for example GET https://api.example.com/v1/products/42.
An API (application programming interface) is a set of rules that lets one piece of software request data or actions from another. In web development, an API usually means a web API: the front end of a website or mobile app sends an HTTP request to a server endpoint such as /api/orders, and the server replies with data, typically in JSON. APIs are how your app shows a map, takes a card payment, logs users in with Google or loads products from a database. This guide explains how APIs work step by step, the main types and architectures (REST, GraphQL, gRPC, webhooks), real examples from everyday web apps, how to secure and document an API, and best practices for building one.
What Is an API?
A web page, mobile app or another server sends an HTTP request to an endpoint, for example GET https://api.example.com/v1/products/42.
It reads the API key or access token in the request headers and confirms the caller is allowed to do this.
Business logic runs: it might read a database, call another service or start a payment.
The server returns a status code (such as 200 OK or 404 Not Found) and a body, usually JSON, for example the product's name, price and stock level.
The front end displays the product, updates the cart or shows an error message.
| Part | What it is | Example |
|---|---|---|
| Endpoint | The URL of the resource | /v1/products/42 |
| Method | What you want to do | GET to read, POST to create, PUT or PATCH to update, DELETE to remove |
| Headers | Extra information about the request | Authorization: Bearer token; Content-Type: application/json |
| Query parameters | Filters or options in the URL | ?category=shoes&page=2 |
| Body | Data sent with POST, PUT or PATCH | A JSON object with the new order details |
| Status code | Result of the request | 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Server Error |
| Response body | Data returned | A JSON object with the product name, price and stock |
| Term | Meaning |
|---|---|
| API | The whole interface: all the operations, rules, data formats and authentication a service offers |
| Endpoint | One specific URL and method in that API, such as POST /orders |
| Web service | An API reached over a network, usually HTTP; all web services are APIs, but not all APIs are web services (for example, browser and operating system APIs) |
| SDK | A ready-made code library that calls an API for you in a given language |
Available to any developer, often with an API key and usage limits. Examples: weather data, maps and currency exchange APIs.
Shared with selected business partners under an agreement, such as a travel supplier giving resellers access to its booking inventory.
Used only inside a company, for example the API your own website and mobile app share to read orders and customer accounts.
Combine several calls into one, such as creating a customer, an order and a payment in a single request, which reduces round trips for mobile apps.
| Architecture | How it works | Best for | Example |
|---|---|---|---|
| REST | Resources at URLs, standard HTTP methods, usually JSON | Most web and mobile apps, public APIs | GET /users/7 returns a user |
| GraphQL | One endpoint; the client asks for exactly the fields it needs | Complex front ends with many related data types | One query returns a user, their orders and reviews |
| gRPC | Binary protocol with strict contracts (Protocol Buffers) | Fast communication between back-end services | Microservices calling each other thousands of times a second |
| SOAP | XML messages with a formal contract (WSDL) | Older enterprise, banking and government systems | Legacy payment or insurance integrations |
| Webhooks | The server calls your URL when an event happens | Notifications and syncing | A payment provider tells your app a payment succeeded |
| WebSockets | A two-way connection that stays open | Real-time chat, live dashboards, games | Live order tracking or stock prices |
| Feature on a website or app | API behind it |
|---|---|
| Sign in with Google or Apple | OAuth 2.0 and OpenID Connect identity APIs |
| Card and UPI payments | Payment gateway APIs such as Stripe, Razorpay or PayPal |
| Maps and delivery tracking | Google Maps Platform or Mapbox APIs |
| Order confirmation SMS and email | Twilio, SendGrid or AWS SES APIs |
| Product search | Algolia or Elasticsearch APIs |
| AI chat or content features | Large language model APIs from providers such as OpenAI, Anthropic or Google |
| Shipping rates and labels | Courier APIs such as Shiprocket, Delhivery, FedEx or UPS |
Product, cart, payment, inventory and shipping APIs connect storefronts, marketplaces and warehouses.
HL7 FHIR APIs exchange patient records, appointments and lab results between hospital systems and patient apps.
Open banking and payment APIs share account data with consent and move money securely.
Tracking, routing and carrier APIs give customers live delivery updates and automate dispatch.
The same API serves the website, mobile apps and partner tools.
Teams reuse ready-made services for payments, maps or messaging instead of building them.
Front-end and back-end teams can work in parallel against an agreed contract.
API-based services can be scaled and updated separately.
Businesses can offer data or services to partners through paid APIs.
List the resources (users, products, orders) and the actions each consumer needs.
Write an OpenAPI specification with endpoints, request and response formats, errors and authentication, and review it with front-end and mobile teams.
Popular choices are Node.js with Express or NestJS, Python with FastAPI or Django REST Framework, Java with Spring Boot, PHP with Laravel and C# with ASP.NET Core.
Implement endpoints, validation and error handling, and add unit, integration and contract tests.
Add authentication, rate limits and HTTPS, then deploy behind an API gateway with logging and monitoring.
Publish interactive documentation and version the API so changes never break existing apps.
| Practice | Why it matters |
|---|---|
| HTTPS everywhere | Encrypts data in transit so tokens and personal data cannot be read |
| Authentication (API keys, OAuth 2.0, JWT) | Confirms who is calling the API |
| Authorisation on every request | Stops users reading or changing other users' data, the most common API flaw in the OWASP API Security Top 10 |
| Input validation | Blocks injection attacks and malformed data |
| Rate limiting and quotas | Prevents abuse, scraping and denial-of-service |
| Minimal responses | Returns only the fields the client needs, reducing data exposure |
| Logging and monitoring | Detects unusual traffic and helps investigate incidents |
| Tool | Used for |
|---|---|
| OpenAPI (Swagger) | Describing REST APIs and generating interactive docs and SDKs |
| Postman | Sending test requests, sharing collections and automated tests |
| Insomnia | Lightweight API testing and debugging |
| GraphiQL and Apollo Studio | Exploring and testing GraphQL APIs |
| k6 and JMeter | Load and performance testing |
Plural nouns for resources (/orders, /orders/123) and HTTP methods for actions.
For example 422 with a message that says which field is invalid.
Return results in pages with limits and cursors.
/v1/ in the path or a version header, with notice before retiring old versions.
Use ETags and cache headers for data that changes rarely.
Repeating the same PUT or DELETE should not cause extra side effects; use idempotency keys for payments.
Related Reading
PerfectionGeeks designs and builds secure, well-documented APIs and connects web and mobile apps to payments, maps, CRMs, ERPs and AI services. Tell us what you need to connect and we will send a plan and estimate.