Resources and nouns in URLs
35 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)ShopLite's first draft had /getProductDetails?pid=1, /fetchAll and /doDelete: every endpoint had its own made-up name, and each new developer had to learn them one by one.
REST: resources, representations and stateless requests
A resource is a thing a REST API offers, such as a product, a customer or an order, with its own URL. Product 1 of ShopLite lives at /api/v1/products/1.
One request names product 1 by its URL and asks for a copy of it.
Example 1 · A resource and its JSON representation
GET /api/v1/products/1 HTTP/1.1Host: localhost:8080Accept: application/jsonHTTP/1.1 200 OK
Content-Type: application/json
{
"id": 1,
"sku": "MOB-RN13",
"name": "Redmi Note 13 5G",
"categoryId": 2,
"categoryName": "Mobiles",
"price": 17999.00,
"stock": 40,
"isActive": true
}What this code does
- The URL names one resource, product 1, and the method GET asks for a copy of it. The request needs nothing else, so it is stateless.
- The body is a representation:
categoryNameis not a column of the products table, it is added because clients need it. The database row and the JSON do not have to match.
The server never sends the database row itself. It sends a representation of the resource: usually JSON with the fields a client needs. Each request is stateless: URL, method, headers and body carry everything the server needs, so the server does not remember the product you looked at last.
REST (Representational State Transfer) is a set of rules for web APIs, not a library or a file format. With the same rules everywhere, a developer who knows /products/1 can guess /customers/1 and /orders/1 without reading anything.
Nouns, not verbs, in URLs
A noun-based URL names the resource and leaves the action to the HTTP method. GET /products reads products and POST /products creates one; the URL stays the same.
Six verb-style URLs, and the same six operations in REST style.
Example 2 · Verb-style URLs and their REST versions
GET /getAllProductsGET /getProductById?id=3POST /addNewProductPOST /updateProductPrice?id=3GET /deleteProduct?id=3GET /getOrdersOfCustomer?customerId=2GET /api/v1/products GET /api/v1/products/3 POST /api/v1/products PATCH /api/v1/products/3 DELETE /api/v1/products/3 GET /api/v1/customers/2/orders
What this code does
- Every verb moved out of the URL into the method. Two URLs are left for products: the collection
/productsand the item/products/3. - The delete was a GET: a crawler following links would have deleted product 3.
DELETEcannot be triggered by following a link./customers/2/ordersis a nested URL, covered in the Nested resources lesson.
Each operation has one fixed shape:
- Read all:
GET /products(not/getAllProducts). - Create:
POST /products(not/addProductor/products/create). - Change one:
PUT /products/3orPATCH /products/3(not/updateProduct?id=3). - Remove one:
DELETE /products/3(notGET /deleteProduct?id=3).
Verb names multiply fast: four operations on five resources give twenty made-up names. Caches, browsers and tools understand methods, not your own words, so a verb in the URL also hides what the request does.
Find the bug
Find the verb in the URL
One line in each list breaks the noun rule. Click it.
Which line has a verb in the URL?
Round 1 of 3GET /deleteProduct?id=3 can be followed by a search-engine crawler or a browser preloading pages, and the product is gone.Collections and items: /products and /products/{id}
A collection URL names the whole set of one resource, such as /products; an item URL adds the id of one member, such as /products/3.
The collection of categories, then one category from it.
Example 3 · Collection URL and item URL
GET /api/v1/categories HTTP/1.1Host: localhost:8080GET /api/v1/categories/2 HTTP/1.1Host: localhost:8080HTTP/1.1 200 OK
Content-Type: application/json
[
{ "id": 1, "name": "Electronics", "parentId": null },
{ "id": 2, "name": "Mobiles", "parentId": 1 },
{ "id": 3, "name": "Laptops", "parentId": 1 },
{ "id": 4, "name": "Accessories", "parentId": 1 },
{ "id": 5, "name": "Books", "parentId": null },
{ "id": 6, "name": "Fashion", "parentId": null },
{ "id": 7, "name": "Home & Kitchen", "parentId": null }
]
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 2,
"name": "Mobiles",
"parentId": 1
}What this code does
- The collection
/categoriesreturns a JSON array of every category; the item/categories/2returns one JSON object. - Both use the plural noun.
parentIdisnullfor top-level categories and1for categories inside Electronics.
In API documents the changing part is written in braces: /products/{id}. The {id} is a path variable, filled with a real id such as 3.
Use plural nouns for both: /products and /products/3, not /product/3. The item reads as "product 3 from the products". Mixing singular and plural (/product/3 but /orders) forces every client to remember which is which.
URL style: lowercase, hyphens, no extensions, ids in the path
URL style rules are the naming rules that keep every address in an API looking the same, so nobody has to guess the spelling.
Six messy URLs, and the clean URL each one should be.
Example 4 · Fixing URL style
GET /API/V1/Products/3GET /api/v1/products/3.jsonGET /api/v1/products?id=3GET /api/v1/orderItems?orderId=16GET /api/v1/Customer_Addresses/1GET /api/v1/products/GET /api/v1/products/3 GET /api/v1/products/3 GET /api/v1/products/3 GET /api/v1/orders/16/items GET /api/v1/customers/1/addresses GET /api/v1/products
What this code does
- The first three all meant product 3; one clean URL replaces them: lowercase, no
.json, the id in the path. - Order items and addresses only make sense inside their order or customer, so they sit under the parent. Multi-word names would use hyphens; the trailing slash is dropped.
ShopLite follows these rules:
- Lowercase letters only:
/products, not/Products(many servers treat paths as case-sensitive). - Hyphens between words:
/delivery-slots, not/deliverySlotsor/delivery_slots. - No file extensions:
/products/3, not/products/3.json; theContent-Typeheader says it is JSON. - No trailing slash and no repeats:
/api/v1/products, not/api/v1/products/.
Query parameters (after ?) are for optional things that narrow a list, such as filters and page numbers. The identity of one resource is part of the path: /products/3, not /products?id=3.
Actions that are not CRUD: cancelling an order
An action sub-resource is a POST URL under one item that runs a business action, such as POST /orders/16/cancel. Action URLs are the only verbs in ShopLite URLs.
Cancel order 16 with one request that has no body.
Example 5 · Cancel as an action sub-resource
POST /api/v1/orders/16/cancel HTTP/1.1Host: localhost:8080HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 16,
"customerId": 7,
"addressId": 9,
"status": "CANCELLED",
"orderedAt": "2026-09-29T16:30:00+05:30",
"items": [
{ "productId": 13, "sku": "FSH-SHOE", "productName": "Running Shoes", "quantity": 1, "unitPrice": 2499.00, "lineTotal": 2499.00 },
{ "productId": 11, "sku": "BK-ATOMIC", "productName": "Atomic Habits", "quantity": 3, "unitPrice": 399.00, "lineTotal": 1197.00 }
],
"total": 3696.00
}What this code does
- The request has no body: the URL already says which order and which action. The response is the whole order after the change, so the client can refresh its screen.
- Behind this one call the server also returned 1 Running Shoes and 3 Atomic Habits to stock. Cancelling order 14, which is
SHIPPED, is refused; the Status codes lesson shows that error.
Cancelling a ShopLite order changes its status and puts every item back into stock, and it is allowed only while the order is still PLACED. That is more than a field change, which is why it is not plain CRUD (Create, Read, Update, Delete).
There are three common designs: (1) PATCH /orders/16 with {"status": "CANCELLED"}, (2) an action sub-resource POST /orders/16/cancel, or (3) a new resource POST /orders/16/cancellations that records who cancelled and why. ShopLite uses (2) for cancel, ship and deliver: each action has its own rules and side effects, and a separate URL keeps them visible and easy to secure. A generic PATCH of status would let a client try any jump, such as CANCELLED back to PLACED.
Next step
Check your understanding
11 quick questions