YouTip LogoYouTip

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
← Restful Api ApplicationRestful Api Intro β†’