Skip to content

URI Design Rules & Guidelines

Follow these rules when designing resource URIs:

The forward slash (/) indicates a hierarchical relationship between resources.

# Good
/universities/123/departments/456/courses
# The hierarchy: university → department → courses

Hyphens (-) improve URI readability for multi-word resource names.

# Good
/api/user-profiles
/api/order-items
# Bad
/api/userprofiles
/api/orderitems

Underscores (_) can be hidden by underline styling in links. Use hyphens instead.

# Good
/api/blog-posts
# Bad
/api/blog_posts

URIs are case-sensitive. Use lowercase to avoid confusion.

# Good
/api/users/123/orders
# Bad
/api/Users/123/Orders

Use singular nouns for singleton resources (specific documents).

# Good - singular for specific item
/api/users/123/profile
/api/planets/earth/atmosphere
# These represent ONE thing, not a collection

Use plural nouns for collection resources.

# Good
/api/books
/api/users
/api/orders
# Bad
/api/book
/api/user
/api/order

Variable path segments should contain resource identifiers.

# Good - ID identifies the spescific resource
/api/books/978-0-13-468599-1
/api/users/john-doe
/api/orders/ORD-2024-001

HTTP methods already indicate the operation. Don’t repeat it in the URI.

# Good - HTTP verb indicates action
GET /api/books/123
POST /api/books
PUT /api/books/123
DELETE /api/books/123
# Bad - redundant action words
GET /api/getBook/123
POST /api/createBook
PUT /api/updateBook/123
DELETE /api/deleteBook/123

Trailing slashes add no semantic value and can cause confusion or duplicate resources.

# Good
/api/books/123
# Bad
/api/books/123/

Use content negotiation (Accept header) instead of file extensions. This keeps URIs clean and flexible.

# Good - use Accept header for format
GET /api/books/123
Accept: application/json
# Bad - format in URI
/api/books/123.json
/api/books/123.xml

11. Use Query Parameters for Filtering, Sorting, and Pagination

Section titled “11. Use Query Parameters for Filtering, Sorting, and Pagination”

Path segments define resource hierarchy. Query strings handle filtering, sorting, and pagination.

# Good - query parameters for non-hierarchical data
/api/books?author=tolkien&sort=title&page=2&limit=20
# Bad - filtering in path segments
/api/books/author/tolkien/sort/title/page/2

Limit hierarchy depth to 2-3 levels for readability. Flatten deep hierarchies using query parameters.

# Good - flattened with query parameter
/api/courses?department=456
# Acceptable - shallow nesting (2 levels)
/api/universities/123/departments
# Avoid - too deep (4+ levels)
/api/universities/123/departments/456/professors/789/courses

If versioning via URI, place the version at the start of the path.

# URI versioning
/v1/api/books
/v2/api/books
# Alternative: Header versioning (keeps URIs clean)
GET /api/books
Api-Version: 2