Hi my blog readers!
Another journal is born! now RX journal about web services!
I have just dived deep in .NET 4.0 technology stack, when this week I was assigned to create web services. As .NET mostly guy, I revisit my skill in creating WCF.
Outside world, many things happened. The need of having REST services with the correct model and incorporating HTTP verbs (not just GET and POST) is becoming crucial and more relevant.
Fortunately, Leonard Richardson has written the REST maturity model as the baseline for us. But Martin Fowler, the best known guy that one popularized DSL and PoEAA (Patterns of Enterprise Application Architecture) helped us to understand REST maturity model.
Martin Fowler described the levels into these:
- Level 0 – RAW HTTP
- Level 1 – Resources (with HTTP binding as endpoints)
- Level 2 – HTTP verbs
- Level 3 – Hypermedia
Level 0 means you’re using RAW HTTP with either GET or POST, but the resulting request and response is plain XML. This is why Martin describes this Level as swamp of POX (Plain Old XML). A good sample of this is .NET Remoting using RPC in .NET 2.0 and above and Java’s RMI. In Level 0, the talks only involves talking to only one endpoint.
Level 1 means you’re considering the request and response as real HTTP object, but the main concern here is talking and requesting specific resources as part of HTTP conversation.
This picture was taken from Martin Fowler’s article:
This means not just specifying endpoint, but we also specify which resources needs to be sent and to have.
Level 2 means incorporating HTTP verbs, meaning that now not only specific resources, but it’s also introducing HTTP verbs with response codes.
This means that Level 2 add more concern on separation of which HTTP verbs are changing states and not changing states.
These HTTP verbs change states:
This HTTP verb does not change state:
Fortunately, WCF in .NET 4.0 is confirmed to have full support of Level 1 and with more care, it also supports Level 2.
This is a small sample of Level 1: (an operation contract of testvalue)
And this is the explanation related to the REST levels:
It’s quite simple in WCF, isn’t it? But when you consider Level 2, you also have to pay attention to the verb and the HTTP returning status codes.
Supports for setting and getting HTTP status code is available in WCF using WebOperationContext.
I’ll dive into WCF supports for Level 2 in the next blog entry about this.
Put it simply, Level 2 concerns about:
- Resource specific (as in Level 1)
- using HTTP verbs
- specifying HTTP status codes (for each HTTP verb used) as a mean to define what is the nature of the resulting resource.
Level 3 add concerns about using HTTP as the transport for Hyper media, means that the data will have the additional information of what is the next destination.
It’s quite elegantly illustrated as below picture:
As you can see, there’s additional information in the forms of links to the resource. This means that the hyperlinks in the data has to be specified.
- WebOperationContext in MSDN Library: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.aspx