- Use kebab-case for URLs
Example:
GET /system-orders
- Use camelCase for Parameters
Example:
PATCH /system-orders/{orderId}
- Plural Name to Point to a resource / collection
Example:
GET /system-orders
- URL Starts With a Collection and Ends With an Identifier
Example:
// Bad - points to a property instead of a resource GET /shops/:shopId/category/:categoryId/price //Good GET /shops/:shopId/ or GET /category/:categoryId
- Use proper HTTP methods to describe an operation
Example:
//Bad POST /update-user/{userId} or GET /getusers //Good PUT /user/{userId} //HTTP Methods for CRUD Functions GET // To retrieve a representation of a resource POST // To create new resources and sub-resources PUT // To update existing resources PATCH // To update existing resources. It only updates the fields that were supplied, leaving the others alone DELETE // To delete existing resources
-
Don’t use database's table_name / collection as a resource name
-
Accept limit and offset Parameters GET operations
Example:
GET /shops?offset=5&limit=5
- Take fields Query Parameter
Example:
// Only return the name, address, and contact of the shops GET /shops?fields=id,name,address,contact
- Use the Relation in the URL For Nested Resources
Example:
// Get the list of all products from shop 2 GET /shops/2/products // Get the details of product 31, which belongs to shop 2 GET /shops/2/products/31
- Use Verbs for Non CRUD operations
Example:
// resend the alert to a user POST /alerts/245743/resend