1
REST API
Cheatsheet
Ragini Pandey
2
Intro
REST (Representational State
Transfer) APIs are the foundation
of web services
They make it easy for different
systems to talk to each other using
HTTP protocol
Ragini Pandey
3
🧑💻 Why REST?
Lightweight and scalable
Simple to implement
Universally supported
Supports multiple data
formats (JSON, XML)
Ragini Pandey
4
REST is Stateless
Meaning every request
Contains all necessary info to process it
Does not rely on server-side session
This Statelessness offer following advantages
Scalability
Reliability
Simplicity
Easy in Debugging & Testing
Ragini Pandey
5
Meaning of Resource
A resource is a specific piece of
information or data that you can
access, change, or interact with
through the API
Think of it as a "thing" that the API
lets you work with
e.g. user, product or order
Ragini Pandey
6
HTTP methods
GET: Read resource
POST: Create new resource
PUT: Replace resource entirely
PATCH: Update part of a
resource
DELETE: Remove resource
Ragini Pandey
7
Examples
REST has it’s own language. The combination
of a resource URL and an HTTP method
defines the action
GET /users – Get all users
GET /users/12 – Get user with ID 12
GET /users/123/posts – Get all posts by user with ID 123
GET /users/123/orders?status=pending – Fetch pending
orders for user 123
POST /users – Create a new user
PUT /users/123 – Update user with ID 123
PATCH /users/123 – Partially update user with ID 123
DELETE /users/1 – Delete user with ID 1
Ragini Pandey
8
Pagination, Filter &
Sort
For handling large datasets
📄 Pagination
GET /users?page=1&limit=20
🔍 Filter
GET /users?role=admin
⬆️ Sort
GET /users?sort=name&order=asc
Ragini Pandey
9
Common Mistakes in
naming endpoints I
1: Using Verbs Instead of Nouns
❌ Mistake ✅ Correct
GET /getUser GET /users
POST /createUser POST /users
2: Using IDs in the Wrong Place
❌ Mistake ✅ Correct
GET /users?id=123 GET /users/123
DELETE /users?user_id=1 DELETE /users/1
Ragini Pandey
10
Common Mistakes in
naming endpoints II
3: Including Actions in Endpoints
❌ Mistake ✅ Correct
DELETE /users/remove/1 DELETE /users/11
4: Over-Nesting Resource URLs
❌ Mistake ✅ Correct
GET
GET /comments?
/users/123/posts/456/comments/
reply_to=10
789/replies/10
💡 Limit nesting to two levels and use
query parameters for related data
Ragini Pandey
11
Common Mistakes in
naming endpoints III
5: Missing Resource Identifiers
❌ Mistake ✅ Correct
PUT /users PUT /users/123
6: Not Following Hierarchical Structure
❌ Mistake GET /posts/123 (fetches a post) but lacks
connection to its parent resource
✅ Correct GET /users/123/posts/456 (fetch a specific
post by user)
Ragini Pandey
12
HTTP Status Codes
✅ 1xx: Informational - Request was received
and the server is continuing the process
✅ 2xx: Success - Indicates the action was
successfully received, understood, and accepted
❌ 3xx: Redirection - Indicates the client must
take additional action to complete the request
❌4xx: Client Errors - Indicates the client made a
mistake in the request
❌5xx: Server Errors - Indicates the server failed
to fulfill a valid request
Ragini Pandey
13
API Versioning
API versioning is the practice of managing changes
in your API while maintaining backward
compatibility for existing clients
It allows you to introduce new features without
breaking current implementations
Start with v1 and increment for breaking changes
Document all versions clearly in your API docs
Use deprecation notices to warn users of outdated
versions
Sunset old versions gradually to avoid disruptions
Ragini Pandey
14
Securing REST APIs
Use HTTPS for secure communication
Implement token-based
authentication (OAuth2, JWT)
Sanitize inputs to prevent injection
attacks
Apply rate limiting to prevent abuse
Ragini Pandey
15
Additional Tools
📑 Testing Tools
Postman
cURL
📜 Documentation Tools
Swagger (OpenAPI)
Postman Collections
Ragini Pandey
16
Similar technologies
Following technologies are used for
communication between systems, but they
serve different purposes and have distinct
characteristics
GraphQL
gRPC (Google Remote Procedure Call)
Socket Programming
Ragini Pandey
17
FOLLOW ME
FOR MORE
Ragini Pandey
@ragini-pandey-dev