Sobes.tech
Senior

Can we implement the same REST endpoints by removing the resource name from the path (e.g., 'news')?

sobes.tech AI

Answer from AI

Technically, it is possible to implement REST endpoints without explicitly specifying the resource name in the path, for example, instead of /news/123, just use /123. However, this contradicts REST conventions and reduces the readability and maintainability of the API.

Reasons why resource names are usually included in the path:

  • Clarity and semantics: The path /news/123 clearly indicates that we are working with the "news" resource and its element with ID 123.
  • Avoiding conflicts: Without a resource name, it is difficult to distinguish between different types of entities if they can have the same ID.
  • Routing convenience: Most frameworks build routes considering resources, which simplifies request handling.

Removing the resource name would require using separate domains, subdomains, or other mechanisms for different data types, complicating the architecture.

Conclusion: it is possible, but not recommended — it will impair support and scalability of the API.

Can we implement the same REST endpoints by removing… - sobes.tech