Posted 12/05/2024

Rest API routers naming best practices

Use Nouns, Not Verbs

Endpoints should represent resources, not actions. For example:

Use HTTP methods (e.g., GET, POST, PUT, DELETE) to define actions on resources.

Pluralize Resource Names

Use plural nouns for collections and singular nouns for specific resources:

Keep Endpoints Hierarchical and Logical

Reflect the relationship between resources in the hierarchy:

Use Lowercase and Hyphens

Resource names should be lowercase and use hyphens (-) instead of underscores (_) for readability:

Avoid Deep Nesting

Keep URLs flat to avoid complexity. Use query parameters for additional filtering:

Avoid File Extensions

Specify response formats using headers (Content-Type) rather than file extensions like .json or .xml.

Be Consistent

Use consistent terminology and patterns across the API to enhance usability. Use Query Parameters for Filtering and Searching

For operations like filtering or sorting, use query parameters: /users?location=USA&sort=name.

Versioning

Include a version, for example in the URI to manage updates gracefully: /v1/users.

Readable and Intuitive Names

Choose intuitive, non-abbreviated names: