Sobes.tech
Junior — Middle

What standards and conventions are applied for naming resources and endpoints in REST API?

sobes.tech AI

Answer from AI

In REST API, it is common to follow certain standards and conventions for resource and endpoint naming:

  • Use nouns in plural form for resources, e.g., /users, /orders.
  • Use lowercase letters and hyphens to separate words, e.g., /user-profiles.
  • Use GET to retrieve resources, POST to create, PUT/PATCH to update, DELETE to delete.
  • Resource identifiers are specified in the path, e.g., /users/123.
  • Use hierarchy for nested resources, e.g., /users/123/orders.
  • Do not use verbs in paths; actions are expressed via HTTP methods.

Example:

GET /products - get list of products
POST /products - create a new product
GET /products/45 - get product with id=45
PUT /products/45 - update product
DELETE /products/45 - delete product

Following these rules makes the API understandable and easy to use.