What Is a REST API? A Simple Explanation for Beginners With Practical Examples
REST APIs explained simply: clients and servers, resources and endpoints, HTTP methods, status codes, JSON, authentication, versioning, pagination, security and how apps and websites use APIs.
- November 10Last updated
- 5min read
- 19sections
- 4trusted sources

On this page
- The restaurant analogy
- Resources and endpoints
- HTTP methods
- A request and a response
- Status codes
- Authentication
- Good API design practices
- Security essentials
- How a business benefits from a good API
- Pagination, filtering and sorting
- Versioning your API
- Errors that help developers
- REST vs GraphQL vs webhooks
- Documentation and testing
- Designing endpoints for a booking app
- Rate limiting and caching
- A tiny API in Node.js
- Glossary
- Frequently asked questions
- An API lets apps and websites request and send data to a server in a standard way.
- REST organizes data as resources with URLs, manipulated through HTTP methods.
- Responses usually come as JSON with status codes that describe the result.
- Authentication, validation and rate limiting are essential for security.
- One good API can power your website, mobile app and integrations at once.
When a delivery app shows your order status, or a website displays prices from an inventory system, an API is doing the work behind the scenes. An API (Application Programming Interface) is the way one piece of software talks to another. REST is the most common style for web APIs.
This guide explains REST APIs in plain language with practical examples, so whether you're learning to code or managing a project, you'll understand what your developers are building.
The restaurant analogy
You (the client) don't walk into the kitchen (the server). You give your order to the waiter (the API), who brings back your food (the response). The menu (documentation) tells you what you can order and how.
Resources and endpoints
REST treats data as resources, each with a URL (an endpoint):
| Resource | Endpoint |
|---|---|
| All products | /api/products |
| One product | /api/products/42 |
| A customer's orders | /api/customers/7/orders |
HTTP methods
| Method | Purpose | Example |
|---|---|---|
| GET | Read data | Get product 42 |
| POST | Create | Create a new order |
| PUT / PATCH | Update | Change order status |
| DELETE | Remove | Delete a saved address |
A request and a response
GET /api/products/42 HTTP/1.1
Host: api.example.com
Authorization: Bearer <token>{
"id": 42,
"name": "Wireless Headphones",
"price": 349,
"currency": "SAR",
"in_stock": true
}Status codes
| Code | Meaning |
|---|---|
| 200 OK | Success |
| 201 Created | Resource created |
| 400 Bad Request | Invalid input |
| 401 Unauthorized | Missing or invalid authentication |
| 403 Forbidden | Authenticated but not allowed |
| 404 Not Found | Resource doesn't exist |
| 429 Too Many Requests | Rate limit exceeded |
| 500 Server Error | Something failed on the server |
Authentication
- API keys for server-to-server access (never in a mobile app).
- Tokens (JWT or OAuth 2.0) for users, sent in the
Authorizationheader. - Short-lived tokens with refresh, and permission checks on every request.
Good API design practices
- Consistent, plural, lowercase resource names.
- Versioning:
/api/v1/so you can evolve without breaking apps. - Pagination for lists:
?page=2&limit=20. - Filtering and sorting:
?category=phones&sort=price. - Clear error messages in a consistent format.
- Documentation with OpenAPI (Swagger) so others can use the API easily.
Security essentials
- HTTPS only.
- Validate and sanitize every input on the server.
- Enforce permissions server-side; never trust the client.
- Rate limiting on login and sensitive endpoints.
- Don't return more data than needed.
- Log and monitor unusual activity.
The OWASP API Security Top 10 lists the most common API risks.
How a business benefits from a good API
One API can power your website, Android and iOS apps, admin dashboard and integrations with accounting or shipping systems. That reduces duplicated work and keeps data consistent everywhere. See the app development guide and SQL vs NoSQL.
Pagination, filtering and sorting
Large collections should never be returned in one response. Common patterns:
GET /api/products?page=2&limit=20
GET /api/products?category=phones&sort=-price
GET /api/orders?status=paid&from=2026-01-01Return metadata such as total count and next page link so clients can navigate.
Versioning your API
Mobile apps stay installed for months, so breaking changes hurt. Use a version in the path (/api/v1/) or a header, keep old versions working for a transition period, and document what changes in each version.
Errors that help developers
Return consistent error bodies:
{ "error": { "code": "VALIDATION_FAILED", "message": "Phone number is invalid", "field": "phone" } }Combine the right status code with a machine-readable code and a human message. Never leak stack traces or database errors.
REST vs GraphQL vs webhooks
| Approach | Best for |
|---|---|
| REST | Most business apps; simple, cacheable, well understood |
| GraphQL | Complex screens that need data from many resources in one call |
| Webhooks | Notifying your server of events (payments, shipping updates) |
Documentation and testing
- Describe endpoints with OpenAPI (Swagger) so frontend and mobile teams can work in parallel.
- Provide example requests and responses.
- Test with Postman or automated tests, including failure cases.
- Monitor response times and error rates in production.
See also Website security checklist.
Designing endpoints for a booking app
| Action | Method and path |
|---|---|
| List doctors | GET /api/v1/doctors |
| Get one doctor | GET /api/v1/doctors/42 |
| Available slots | GET /api/v1/doctors/42/slots?date=2026-11-20 |
| Create a booking | POST /api/v1/bookings |
| Cancel a booking | DELETE /api/v1/bookings/1001 |
| Update profile | PATCH /api/v1/me |
Nouns for resources, HTTP methods for actions, and consistent plural naming keep the API predictable.
Rate limiting and caching
Protect your API with rate limits (for example, a maximum number of requests per minute per user or IP) and return 429 Too Many Requests when exceeded. Use caching headers such as Cache-Control and ETag for data that doesn't change often, like a list of services, to reduce server load and speed up apps.
A tiny API in Node.js
import express from 'express';
const app = express();
app.use(express.json());
const services = [{ id: 1, name: 'Web design' }, { id: 2, name: 'App development' }];
app.get('/api/v1/services', (req, res) => res.json(services));
app.post('/api/v1/leads', (req, res) => {
const { name, phone } = req.body;
if (!name || !phone) return res.status(422).json({ error: { code: 'VALIDATION_FAILED' } });
res.status(201).json({ ok: true });
});
app.listen(3000);This small example shows resources, methods, JSON bodies, validation and status codes in about a dozen lines.
Glossary
| Term | Meaning |
|---|---|
| Endpoint | A URL where the API accepts requests |
| Payload / body | Data sent with a request or response |
| Header | Metadata such as content type or authorization |
| Token | A credential proving who is calling |
| Idempotent | Repeating the request has the same effect (GET, PUT, DELETE) |
| Webhook | The server calls your URL when an event happens |
Frequently asked questions
What's the difference between REST and GraphQL?
REST uses multiple endpoints for resources; GraphQL uses a single endpoint where the client specifies exactly what data it needs. Both are valid; REST is simpler and more common.
Do mobile apps need an API?
Almost always. The app talks to the server through an API to sign in, load data and save actions.
Can I test an API without coding?
Yes, with tools like Postman or Insomnia, or simple GET requests in your browser.
What is JSON?
A lightweight text format for data, readable by humans and easy for every programming language to parse.
Is REST the same as HTTP?
No. HTTP is the protocol used to send requests and responses; REST is a style of designing APIs on top of HTTP using resources and standard methods.
What format do REST APIs use?
Most modern REST APIs use JSON because it's lightweight and easy to read in every programming language.
Do mobile apps talk to the database directly?
They shouldn't. Apps call an API, and the API validates requests, applies business rules and talks to the database securely.

Web & App Development
Secure, well-documented APIs that power your website, app and integrations.
Keep reading
Web Design & DevelopmentSQL vs NoSQL: How to Choose the Right Database for Your Website or App
A clear guide to SQL and NoSQL databases: how they work, MySQL, PostgreSQL, MongoDB, Firestore and Redis compared, when to choose each, design tips, scaling, backups and security.
5 min read
App DevelopmentMobile App Development in 2026: The Complete Guide From Idea to Launch and Growth
The complete guide to building a mobile app: validation, MVP scope, cost drivers, Flutter vs native, UI/UX, development process, security, Google Play and App Store publishing, and growth.
17 min read
Web Design & DevelopmentClean Code: 12 Practices That Make Your Code Easy to Read, Change and Maintain
Twelve practical clean code practices: meaningful names, small functions, single responsibility, DRY, clear error handling, comments that matter, consistent formatting, tests, refactoring and code reviews.
5 min read