Why Your API's URLs Matter More Than You Think
Imagine opening a new codebase and finding endpoints like /getUserData, /createNewBike, and /deleteSparePartById. It works, technically. But it's clunky, inconsistent, and it screams 'this API wasn't designed — it just happened.' Now imagine instead finding /users, /bikes, and /spares, each responding to standard HTTP verbs like GET, POST, PUT, and DELETE. That second version isn't just prettier — it's predictable, and predictability is exactly what makes an API a joy to use.
This is the core idea behind resource-based URIs, one of the foundational principles of REST (Representational State Transfer) API design. If you're building backend services with FastAPI and Python, understanding this concept isn't optional — it's essential to writing APIs that scale, that new developers can onboard to quickly, and that don't collapse under their own complexity six months down the line.
In this guide, we'll break down what resource-based URIs are, how they differ from action-based endpoints, and how you can apply these principles to your own FastAPI projects using a practical, real-world example.
Action-Based vs. Resource-Based URIs
Before REST became the dominant API paradigm, many APIs were designed around actions — essentially, remote function calls disguised as URLs. You'd see endpoints like:
/getAllBrands/addNewBike/updateSparePart/removeBrandById
This is called an action-based URI design. Each endpoint describes an operation rather than a resource, which means the HTTP method becomes almost irrelevant — everything is typically sent as a POST request, regardless of whether you're reading, creating, updating, or deleting data.
The problem? This approach quickly becomes inconsistent. Every developer on the team might name their endpoints slightly differently, and the API surface grows messier over time. There's no shared convention to lean on.
Enter Resource-Based URIs
A resource-based URI flips this thinking. Instead of naming endpoints after actions, you name them after the resources (nouns) they represent, and you let the HTTP method communicate the action. So instead of four separate endpoints for brands, you get one consistent path:
GET /brands— retrieve all brandsPOST /brands— create a new brandGET /brands/{id}— retrieve a specific brandPUT /brands/{id}— update a specific brandDELETE /brands/{id}— delete a specific brand
Notice how the URI never changes based on the operation — only the HTTP verb does. This is the essence of clean, scalable REST API design.
A Practical Example: Brands, Bikes, and Spares
Let's ground this in a real scenario. Suppose you're building a showroom management system with three core entities: brands, bikes, and spare parts. Each bike belongs to a brand, and each spare part belongs to a bike. This parent-child relationship is incredibly common in real-world applications, and it's a great way to understand how resource hierarchies should be modeled in your URI structure.
Designing the Parent Resource
Brands sit at the top of the hierarchy, so they get the simplest, most direct resource path:
GET /brandsGET /brands/{brand_id}POST /brandsPUT /brands/{brand_id}DELETE /brands/{brand_id}
Designing Child Resources
Bikes belong to a brand, so their URIs should reflect that relationship by nesting under the parent resource:
GET /brands/{brand_id}/bikes— all bikes for a specific brandGET /brands/{brand_id}/bikes/{bike_id}— a specific bikePOST /brands/{brand_id}/bikes— add a new bike to a brand
Following the same logic, spare parts belong to a bike, so they nest one level deeper:
GET /brands/{brand_id}/bikes/{bike_id}/sparesGET /brands/{brand_id}/bikes/{bike_id}/spares/{spare_id}
This nested structure immediately communicates the relationship between resources just by reading the URI — no documentation required. Anyone looking at /brands/3/bikes/12/spares instantly understands they're looking at spare parts belonging to bike 12, which belongs to brand 3.
Best Practices for Naming Resource-Based URIs
Once you understand the core concept, a few naming conventions will keep your API consistent and professional:
- Use plural nouns for collections:
/bikesinstead of/bike. This keeps things predictable whether you're fetching one item or many. - Avoid verbs in the URI. Let the HTTP method (GET, POST, PUT, DELETE) express the action, not the path itself.
- Use lowercase and hyphens for multi-word resources (e.g.,
/spare-partsrather than/SparePartsor/spare_parts). - Keep nesting shallow. Two or three levels of nesting (like brand → bike → spare) is usually the practical limit before URIs become unwieldy.
- Use path parameters for identifiers (
/bikes/{id}) and query parameters for filtering, sorting, or pagination (/bikes?brand=yamaha&sort=price).
These conventions map naturally onto how FastAPI structures routes. In a well-organized FastAPI project, each resource typically gets its own router file — a brands.py, bikes.py, and spares.py — keeping your endpoint logic modular and easy to navigate, much like the folder structure conventions used in scalable full-stack Python applications.
Understanding API Maturity: The Richardson Maturity Model
A helpful way to evaluate how 'RESTful' your API really is comes from the Richardson Maturity Model, which breaks REST adoption into four levels:
- Level 0: A single URI and a single HTTP verb (usually POST) handles everything. This is essentially RPC over HTTP — not RESTful at all.
- Level 1: Multiple URIs exist for different resources, but only one HTTP method is used across all of them.
- Level 2: Multiple URIs and multiple HTTP verbs (GET, POST, PUT, DELETE) are used correctly according to their semantic meaning. This is where most well-designed REST APIs, including the brand/bike/spare example above, comfortably sit.
- Level 3: Adds HATEOAS (Hypermedia as the Engine of Application State), where API responses include links guiding the client to related actions and resources — making the API self-descriptive and discoverable.
Most production APIs aim for Level 2, since it strikes the right balance between structure and simplicity. Level 3 is powerful but adds complexity that isn't always necessary unless your API needs to be highly dynamic or self-navigating.
Why This Matters for Real Projects
Resource-based URI design isn't just an academic exercise — it directly impacts how maintainable and scalable your backend becomes. Clean, consistent naming conventions make it easier to:
- Onboard new developers without extensive documentation
- Generate accurate API documentation automatically (something FastAPI does beautifully with its built-in OpenAPI support)
- Reduce bugs caused by inconsistent or ambiguous endpoint behavior
- Scale your API as new resources and relationships are added
These principles are covered in depth in the Full Stack Python Architect: FastAPI + React + Vibe Coding course, where you'll walk through resource-based URI design using practical examples like brands, bikes, and spare parts, while also exploring how these concepts fit into a real FastAPI project structure, including routers, schemas, and models.
Key Takeaways
Designing clean REST API endpoints comes down to one central shift in thinking: name your URIs after resources, not actions. Let HTTP methods do the work of expressing intent. Structure your nested resources to reflect real-world relationships, keep your naming consistent, and evaluate your API's maturity using models like Richardson's to identify areas for improvement.
Whether you're building a small internal tool or a large-scale microservices architecture, mastering resource-based URI design will make your FastAPI applications easier to build, easier to document, and — most importantly — easier for other developers (including future you) to use.
Featured Video
[Video Embed Placeholder: RESTFUL API – Resource Based URIs Lecture]
If you'd like a deeper, hands-on walkthrough of these concepts — including live coding examples with FastAPI routers, nested resources, and the Richardson Maturity Model — check out the full Full Stack Python Architect: FastAPI + React + Vibe Coding course, where these ideas are built out step by step into a complete, production-style application.