Question

I am looking for some good links with best practices and sample code on creating RESTful web services using .NET.

Also, any other input you might have regarding REST would be greatly appreciated.

Was it helpful?

Solution

ADO.Net Data Servcies makes it really easy to build and consume RESTful web services in the .Net world but nevertheless understanding the concepts is important. Compared to WCF (which added REST support later), ADO.Net Data Services was built primarily for REST.

Guidelines for Building RESTful Web Services has all the info on the resources you need.

This is another useful blog entry:

The uniform interface constraints describe how a service built for the Web can be a good participant in the Web architecture. These constraints are described briefly as follows :

1) Identification of resources: A resource is any information item that can be named and represented (e.g. a document, a stock price at a given point in time, the current weather in Las Vegas, etc). Resources in your service should be identified using URIs.

2) Manipulation of resources via representations: A representation is the physical representation of a resource and should correspond to a valid media type. Using standard media types as the data formats behind your service increases the reach of your service by making it accessible to a wide range of potential clients. Interaction with the resource should be based on retrieval and manipulation of the representation of the resource identified by its URI.

3)Self-descriptive messages: Following the principles of statelessness in your service's interactions, using standard media types and correctly indicating the cacheability of messages via HTTP method usage and control headers ensures that messages are self descriptive. Self descriptive messages make it possible for messages to be processed by intermediaries between the client and server without impacting either.

4)Hypermedia as the engine of application state: Application state should be expressed using URIs and hyperlinks to transition between states. This is probably the most controversial and least understood of the architectural constraints set forth in Roy Fielding's dissertation. In fact, Fielding's dissertation contains an explicit arguments against using HTTP cookies for representing application state to hammer this point home yet it is often ignored.

OTHER TIPS

Windows Communication Foundation supports REST model since .NET 3.5.

You can find documentation and code samples on MSDN:

REST and POX

Some resources to learn REST:

The best introduction I have read is the RESTful Web Services book, which goes beyond explaining the model and principles and actually shows you how to design a RESTful web service. Most useful is its checklist for how to write/specify an REST API:

  1. Figure out the data set [i.e. specify the data model].
  2. Split the data set into resources. For each kind of resource:
  3. Name the resources with URIs.
  4. Expose a subset of the uniform interface [i.e. specify which HTTP methods are used and what they do].
  5. Design the representations(s) accepted from the client [e.g. the XML format you can PUT or POST].
  6. Design the representations(s) served to the client [e.g. the XML you get back].
  7. Integrate this resource into existing resources, using hypermedia links and forms.
  8. Consider the typical course of events: what's supposed to happen? [This is like a use case main success scenario.]
  9. Consider error conditions. [This is like use case exception scenarios.]

The articles from the "RESTful Web" series at xml.com are a great introduction.

The author (Joe Gregorio, of The Atom Publishing Protocol fame) also regularly publishes insightful articles about all things REST on his weblog. "RESTify DayTrader" (REST Architecture applied to a benchmark stock trading application) is a good starting point. I also like "Why so many Python web frameworks?", which shows the implementation of a small restful web framework in Python.

When I began developing REST web services I read REST API Design Rulebook from Mark Masse. Once you know the basics and the theory, you will be able to implement REST with WCF, HTTPListener or ServiceStack. All these frameworks are .NET and quite good documented...

I would recommend to you service stack (http://www.servicestack.net/) there is enough information on the web to get started.

WCF offers the ASP.NET web API, it is OK, but I don't use it.

In any case, there is no good REST framework today, you have to choose one that you find easy to use and then apply the theory that you learned from the book.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top