Today on endpoint.tv – The REST Collection Template
One of the more interesting (challenging?) things we did with the WCF REST Starter Kit is the REST Collection Service Template. The idea behind this template was to produce a service that allows you read/write access to a service using a simple REST style interface. The idea is to provide both a contract and base class that takes care of most of the REST-“isms” and you simply override the methods to support your business logic.
And how does this template help?
- Provides the URI templates for your service based on a very simple model of a resource per service with an ID parameter
- Supports content negotiation with a query string parameter i.e. “?format=json”
- Supports HTTP status codes such as 201 – “Created” when you add a new item or 404 – Not Found when you try to update or delete an item that does not exist
- Supports append to the collection via POST
What do you think?
One of the reasons we are putting this out to the community in a Codeplex release is that we want to get your constructive feedback. Here is a good starting point. Answer this question
What is wrong with this template?
I’m not tying to sound defensive, I just want to know what you really think.
We know that it isn’t perfect, but if you don’t like it, what do you not like about it? How can we improve it?
The best way to answer these questions is to give it a test drive by running through Lab 3 from the WCF REST Starter Kit Hands On Labs so download and give it a go. You can help us make it better.
Comments
Anonymous
April 06, 2009
Hi Ron, Great templates. I have what is probably a stupid question, so please forgive me as I am relatively new to REST and .net. I would like to process a slightly different URL, but I am not sure how to do it. For example I might want to process the following URL: www.example.com/author/12/books for which I would like to return all of the books for the author with an id = 12. Is there an easy way to accomplish this without having to modify the base class or interface? Thanks, KevinAnonymous
April 07, 2009
@Kevin - Absolutely - check out the REST Starter Kit Hands On Lab #2 which shows you how to use the IIS 7 URL Rewrite Module - that should do the trick.Anonymous
April 24, 2009
Hello Ron, I love the REST Collection Service Template but I cannot figure out waht I would need to do to expose multiple resources. It is quite easy to implement CRUD operations around a collection of a single resource. However, I am at a loss as what the next steps are to expose other collections of resources? Example // Returns All Authors http://www.ex.com/authors //Returns All Books http://www.ex.com/books // Returns All Books for a Single Author http://www.ex.com/authors/{authorId}/Books Thanks, Alfred