REST-Based service design
Series [ REST-based Service Design ] Tags [ REST API ]
Just wanted to walk through a quick REST-style API design exercise. Let’s suppose I want a service that lets folks maintain a list of favorite foods. Just as a quick strawman design, let’s walk through some URIs and supported operations:
http://host:port/path/{userid}/favoritesGETon this URI returns a list of the current user’s favorites. List might be empty.PUTon this URI overwrites an existing list of favorites.DELETEon this URI sets the list of favorites to the empty list.
http://host:port/path/{userid}/favorites/{food}GETon this URI returns something (really, we just want a 200 status code) if the food is a favorite, or returns 404 if it is not.DELETEon this URI un-favorites the food for the user.PUTon this URI makes the food a favorite.
So, questions for the audience:
- Does this look reasonable?
- Does the use of
PUTlook right, or would you usePOSThere? - How about the use of
DELETEto set the full list to the empty list? Does it make sense toDELETEa URI and then be able toGETit and have something be there?