While creating URI for web services, what are the best practices that needs to be followed?
Below is the list of best practices that need to be considered with designing URI for web services:
- While defining resources, use plural nouns. Example: To identify user resource, use the name “users” for that resource.
- While using the long name for resources, use underscore or hyphen. Avoid using spaces between words. For example, to define authorized users resource, the name can be “authorized_users” or “authorized-users”.
- The URI is case-insensitive, but as part of best practice, it is recommended to use lower case only.
- While developing URI, the backward compatibility must be maintained once it gets published. When the URI is updated, the older URI must be redirected to the new one using the HTTP status code 300.
- Use appropriate HTTP methods like GET, PUT, DELETE, PATCH, etc. It is not needed or recommended to use these method names in the URI. Example: To get user details of a particular ID, use
- Use the technique of forward slashing to indicate the hierarchy between the resources and the collections. Example: To get the address of the user of a particular id, we can use: