I have been having a debate about what to do with a trailing slash in a RESTful API.
Lets say I have a resource called dogs and subordinate resources for individual dogs. We can therefore do the following:
GET/PUT/POST/DELETE http://example.com/dogs
GET/PUT/POST/DELETE http://example.com/dogs/{id}
But what do we do with the following special case:
GET/PUT/POST/DELETE http://example.com/dogs/
My personal view is that this is saying send a request to an individual dog resource with id = null
. I think the API should return a 404 for this case.
Others say the request is accessing the dogs resource i.e. the trailing slash is ignored.
Does anyone know the definitive answer?
dogs
anddogs/
as equivalent. For me it's clear thatdogs/
is a directory containing the individual dogs. Its less clear whatdogs
is, but I'd treat it as equivalent, just like most webservers accept accesses to directories without the trailing/
.