RESTful URI trailing slash or no trailing slash

The following urls:

http://example/foo
http://example/foo/

Are NOT the same url. Caches will store them separately. So in that sense there is a real difference. Normalizing URLs will not strip them.

Every URI (ending with slash or not) will point to a resource.

As far as I know there is no specific recommendation to use either. Some protocols (such as WebDAV) use it to suggest that URLs ending with a slash imply that it’s a collection.

One small benefit of ending with a slash is that relative URLs inside the document (that don’t start with slash) will refer to items in the collection. Taking advantage of this means that clients need to correctly resolve relative urls, which is not always true.

Most APIs I’ve seen don’t end with slashes. To some people, ending with a slash (and requiring this) might be surprising behavior.

No official sources, because I don’t think they exist. I’m fairly deep into standards, so I’m reasonably confident about this.

Leave a Comment