Restful Api Url
# URL Design Guidelines
## Resource-Oriented URL Design
RESTful API URLs should represent "resources" rather than "actions".
Think of URLs as library shelf labels, they tell you where to find what resources.
### Good Design β
GET /api/users # Get all users
GET /api/users/123 # Get user with ID 123
POST /api/users # Create new user
PUT /api/users/123 # Update user 123
DELETE /api/users/123 # Delete user 123
### Poor Design β
GET /api/getUsers # Verb appears in URL
POST /api/createUser # Action-oriented rather than resource-oriented
GET /api/user/delete/123 # Confusing structure
* * *
## URL Naming Conventions
### Use Nouns Instead of Verbs
* β
GET /api/books
* β GET /api/getBooks
### Use Plural Forms
* β
GET /api/users
* β GET /api/user
### Use Lowercase Letters
* β
GET /api/user-orders
* β GET /api/UserOrders
### Use Hyphens to Separate Words
* β
GET /api/user-profiles
* β GET /api/user_profiles
* β GET /api/userProfiles
* * *
## Nested Resources
When resources have a hierarchical relationship, you can use nested URLs:
// Get all orders for user 123
GET /api/users/123/orders
// Get order 456 for user 123
GET /api/users/123/orders/456
// Create new order for user 123
POST /api/users/123/orders
### Nesting Level Recommendations
!(#)
## Query Parameters
Used for filtering, sorting, and pagination:
javascript// Pagination
GET /api/users?page=1&limit=10
// Filtering
GET /api/users?status=active&city=beijing
// Sorting
GET /api/users?sort=created_at&order=desc
// Search
GET /api/users?search=Zhang San
* * *
## API Versioning
To maintain backward compatibility, APIs need versioning:
### URL Path Versioning
GET /api/v1/users
GET /api/v2/users
### Request Header Versioning
GET /api/users
Accept: application/vnd.api+json;version=1
YouTip