URI Naming
A URI is the name of a resource. Consistent naming lets a developer guess the next endpoint correctly without reading the docs — the highest compliment an API can earn.
The conventions
Section titled “The conventions”- Nouns, not verbs —
/articles, never/getArticles. The method is the verb. - Plural collections —
/articlesis the collection;/articles/42is one item in it. Pick plural and stick with it. - Lowercase with hyphens —
/blog-posts, not/blogPostsor/Blog_Posts. Paths are case-sensitive in spirit; keep them lowercase to avoid surprises. - IDs in the path, not the query —
/articles/42, not/articles?id=42. The query string is for filtering a collection, not identifying an item. - No file extensions —
/articles/42, not/articles/42.json. Use theAcceptheader for format negotiation. - No trailing slash convention — choose with or without and be consistent (most APIs omit it).
Good vs. not
Section titled “Good vs. not”GET /articles # collectionGET /articles/42 # one itemGET /articles/42/comments # that item's commentsGET /articles?status=draft # filtered collection
# Avoid:GET /getArticlesGET /article/42 # inconsistent singularGET /articles/42.jsonGET /articles?articleId=42 # identity belongs in the path