REST API
Beginner
1 min read
Resource Naming and URL Design
Example
# ----- Good URL design -----
# Collections (plural nouns)
GET /products # list all products
POST /products # create a product
# Single resources (noun + id)
GET /products/99 # get product 99
PUT /products/99 # replace product 99
PATCH /products/99 # partial update
DELETE /products/99 # delete
# Nested resources (max 2 levels)
GET /users/7/orders # orders for user 7
GET /users/7/orders/12 # specific order
# Filtering, sorting, pagination via query string
GET /products?category=shoes&maxPrice=100
GET /products?sort=price&order=asc
GET /products?page=2&limit=20
GET /products?cursor=eyJpZCI6NTB9&limit=20
# Search
GET /search?q=running+shoes&type=product
# ----- Anti-patterns to avoid -----
# GET /getProducts <- verb in URL
# POST /products/delete/99 <- wrong method
# GET /users/7/posts/3/comments/9/likes/1 <- too deep
# GET /api/v1/get_user_data?user_id=7 <- snake_case + verb
Related Resources
REST API Reference
Complete tag & property list
REST API How-To Guides
Step-by-step practical guides
REST API Exercises
Practice what you've learned
More in REST API