Building a REST API is a core skill for any backend developer in India today. Whether you're aiming for a βΉ6-8 LPA role at a service giant like TCS or Infosys, or a more competitive position at a product company like Flipkart or Zomato, your ability to design clean, scalable, and secure APIs will be tested in interviews and on the job. For freshers, understanding the principles behind good API design is often more valuable than just knowing how to write one.
This guide breaks down REST API best practices into actionable steps, using examples relevant to the Indian tech ecosystem. We'll focus on the design patterns that make your API intuitive for other developers, efficient under load, and secure enough to handle real user data.
What is REST and Why Does Design Matter?
REST (Representational State Transfer) is an architectural style, not a strict protocol. It uses standard HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources, which are identified by URLs. A well-designed REST API is like a well-organized library: easy to navigate, predictable, and consistent.
For Indian freshers, this is critical because:
- Interview Focus: System design rounds frequently include questions like "Design an API for a food delivery app" or "How would you structure endpoints for an e-commerce cart?"
- Collaboration: In large Indian IT teams, your API will be consumed by frontend teams, mobile developers, and other services. A messy API slows everyone down.
- Scalability: Startups like Razorpay or Swiggy handle millions of API calls daily. A solid foundational design is key to handling that scale.
Core Principles of RESTful Design
1. Use Nouns, Not Verbs, in Endpoint Paths
Your API endpoints should represent resources (nouns), not actions (verbs). The HTTP method you use defines the action.
Avoid:
GET /getUsersPOST /createProductDELETE /deleteOrder/123
Use Instead:
GET /usersPOST /productsDELETE /orders/123
This makes your API predictable. If you know GET /orders fetches all orders, it's intuitive that GET /orders/456 fetches a specific one.
2. Leverage HTTP Methods Correctly
Each HTTP method has a specific semantic meaning. Using them correctly is a hallmark of a well-designed API.
- GET: Retrieve a resource or a collection. Should never change server state.
- POST: Create a new resource. (e.g., submitting a form, placing an order).
- PUT: Update an existing resource by replacing it entirely.
- PATCH: Apply a partial update to a resource.
- DELETE: Remove a resource.
For a /tasks resource in a project management app:
GET /tasks- List all tasks.POST /tasks- Create a new task (send data in request body).GET /tasks/{id}- Get details of task #id.PUT /tasks/{id}- Replace all details of task #id.PATCH /tasks/{id}- Update only thestatusfield of task #id.DELETE /tasks/{id}- Delete task #id.
3. Use Plural Resource Names
Stick to plural nouns for collections. It's more readable and avoids ambiguity.
- Use
/users, not/user - Use
/products, not/product - Use
/orders/123/items, not/order/123/item
Structuring Responses and Handling Errors
1. Consistent Response Format
Wrap your data in a consistent JSON structure. This helps frontend developers parse responses easily. A common pattern is:
{
"success": true,
"data": { ... }, // or [ ... ] for arrays
"message": "Operation successful", // optional
"error": null
}
In case of an error:
{
"success": false,
"data": null,
"message": "Product not found",
"error": {
"code": "RESOURCE_NOT_FOUND",
"details": "The product with ID 999 does not exist."
}
}
2. Use Standard HTTP Status Codes
Don't just return 200 OK for everything. Status codes instantly communicate the result of an API call.
- 2xx Success:
200 OK- Generic success for GET, PUT, PATCH.201 Created- Successfully created a new resource (after POST). Include aLocationheader with the new resource's URL.204 No Content- Success, but no body to send (common for DELETE).
- 4xx Client Errors:
400 Bad Request- Server cannot process the request (e.g., malformed JSON).401 Unauthorized- Authentication is required and has failed.403 Forbidden- Server understands the request but refuses to authorize it.404 Not Found- Resource doesn't exist.429 Too Many Requests- Rate limiting.
- 5xx Server Errors:
500 Internal Server Error- A generic catch-all for server failures.
Advanced Practices for Scalability and Security
1. Implement Filtering, Sorting, and Pagination
When your /products endpoint grows to have 10,000 items, returning all of them is inefficient. Use query parameters for these operations.
- Filtering:
GET /products?category=electronics&minPrice=10000 - Searching:
GET /products?q=laptop - Sorting:
GET /products?sort=-price,rating(descending price, then ascending rating) - Pagination:
GET /products?page=2&limit=25- Always include pagination metadata in the response:
totalItems,totalPages,currentPage,itemsPerPage.
- Always include pagination metadata in the response:
2. Version Your API
When you need to make breaking changes (like renaming a field), do not break existing apps. Version your API from the start.
- URL Versioning (Simple):
https://api.example.com/v1/products - Header Versioning:
Accept: application/vnd.example.v1+json
For most Indian fresher projects, URL versioning (/v1/) is perfectly acceptable and clear.
3. Security is Non-Negotiable
APIs are prime targets for attacks. Basic security is a must-know for any role, especially in fintech (Paytm, Zerodha) or e-commerce.
- Always Use HTTPS: Never send data over plain HTTP.
- Validate Input: Sanitize and validate all request data on the server-side to prevent SQL injection and XSS.
- Implement Authentication & Authorization: Use standards like JWT (JSON Web Tokens) for stateless authentication. Never put sensitive data (like passwords) in URLs or response headers.
- Rate Limiting: Protect your API from abuse by limiting how many requests a client can make in a given time window (e.g., 100 requests/hour per API key).
Tools and Learning Resources for Indian Developers
You don't need expensive software to learn and practice. Hereβs a toolkit to get started:
- Design & Documentation: Use Postman (free tier) or Swagger/OpenAPI to design, document, and test your APIs before writing code.
- Backend Frameworks:
- Node.js: Express.js is incredibly popular and great for beginners. Check out CodeWithHarry's or Apna College's Express.js tutorials on YouTube.
- Python: Django REST Framework or Flask. NPTEL's "Programming, Data Structures And Algorithms Using Python" course is a fantastic free resource.
- Java: Spring Boot is the industry standard in many Indian service companies. Jenny's Lectures and Gate Smashers have excellent Spring Boot playlists.
- Practice Platforms: Build real projects. Clone the core API of Swiggy (restaurants, menus, orders) or a ticket booking system. Deploy it for free on Render or Cyclic.
Next Steps
Mastering API design is a journey. Start by building a simple CRUD API for a blog or a todo app, then gradually incorporate filtering, pagination, and JWT authentication.
To solidify these concepts with hands-on projects, browse our curated list of free backend development courses. You can also find in-depth guides on specific frameworks like Node.js and Express or Spring Boot to turn these design principles into working code.
EXCERPT--- Learn REST API design best practices for Indian freshers. Build scalable, secure APIs with proper HTTP methods, error handling, and pagination to ace interviews at companies like TCS and Flipkart.
Share this article
Keep learning on UnboxCareer
Explore free courses, certificates, and career roadmaps curated for Indian students.



