We're developing a REST API for our platform. Let's say we have organisations
and projects
, and projects
belong to organisations
.
After reading this answer, I would be inclined to use numerical ID's in the URL, so that some of the URLs would become (say with a prefix of /api/v1
):
/organisations/1234
/organisations/1234/projects/5678
However, we want to use the same URL structure for our front end UI, so that if you type these URLs in the browser, you will get the relevant webpage in the response instead of a JSON
file. Much in the same way you see relevant names of persons and organisations in sites like Facebook or Github.
Using this, we could get something like:
/organisations/dutchpainters
/organisations/dutchpainters/projects/nightwatch
It looks like Github actually exposes their API in the same way.
The advantages and disadvantages I can come up with for using names instead of IDs for URL definitions, are the following:
Advantages:
- More intuitive URLs for end users
- 1 to 1 mapping of front end UI and JSON API
Disadvantages:
- Have to use unique names
- Have to take care of conflict with reserved names, such as
count
, so later on, you can still develop an API endpoint like/organisations/count
and actually get the number of organisations instead of the organisation calledcount
.
Especially the latter one seems to become a potential pain in the rear. Still, after reading this answer, I'm almost convinced to use the string identifier, since it doesn't seem to make a difference from a convention point of view.
My questions are:
- Did I miss important advantages / disadvantages of using strings instead of numerical IDs?
- Did Github develop their string-based approach after their platform matured, or did they know from the start that it would imply some limitations (like the one I mentioned earlier, it seems that they did not implement such functionality)?