Published on 14-05-2021
The URLs of a RESTful API are an important aspect of the user interface for developers that are trying to use the API. They should be consistent and logical, conforming to the REST principals as much as possible.
In the RESTful principles every URL identifies a resource. If an API gives access to companies, this means every company can be identified by an url, for example
example.com/api/companies/1.json. Interacting with that URL using different HTTP methods gives the developer varous abilities:
As stated previously, every URL indentifies a resource. This doesn't mean other information is not allowed. It is very useful to include the api version in the URL as well. For example, instead of using
api.example.com/companies/1.json to identify a company with identifier 1, you could also choose to use
example.com/api/v1/companies/1.json. This can be helpful if you later want to introduce non-backward compatible changes that might break old clients. The new API version will have new URLs for the resources which can be used by clients that conform to the new API specification.
No credit card required