Sunday, May 10, 2009

Book Review - RESTful .NET

Since we are using REST on top of WCF on my current project I was glad to see that this book had been written as I was hoping it would answer some questions I had.

However my first issue with this book was the title. As I say we're using WCF but WCF isn't the only way to implement REST in .NET, however the book does not take the time to evaluate alternatives (including building RESTful applications on top of ASP.NET MVC) so RESTful WCF would have been a more accurate title.

In fact if we wanted to truly represent the books focus I think we would call it WCF REST because the primary focus is on WCF. There was a lot of WCF detail in here, starting from chapter 2, and personally I found some if quite boring especially where the author has chosen to put in property listings of some key WCF classes. I just don't find that sort of content all that useful and I'd have expected a lot of it to be in an appendix at best.

However the WCF focus has some other implications. Take HATEOS which is an important part of REST, my company has been lucky enough to have Sebastien Lambla and Alan Dean in our office and both emphasized its importance. However there is almost no discussion of it in the book, and the reason for this becomes clear on page 246 where the author states that although hypermedia is important in REST it isn't covered in the book because WCF has poor support for it. As I say we're using WCF so I knew that WCF's support for links in normal representations was non-existent, but I do consider it a flaw of the book and in my view the author would have been better stating this big problem up-front or tried to add framework to make linking a lot easier (something Seb did for us).

Strangely the author actually states that he actually avoids discussing custom infrastructure code because it takes away from learning about the technology (page 97). Personally I would prefer the book if had a focus on REST and how to get the advantages of REST using WCF, low level WCF plumbing/architecture is a necessary evil not something I want to read much about and more importantly if we need extra framework then I'd like to see it discussed.

I also thought it was doubly odd that chapter 9 discussed "Using Workflow to Deliver REST Services", all centred around Windows Workflow, when to me when I see the words workflow in a REST book I'm again thinking of HATEOS (the RESTbucks example at InfoQ shows this approach brilliantly and will form part of a rival book).

Before wrapping up I also wanted to identify one bit of the book where the advice is very questionable. Chapter 10 is called "Consuming RESTful XML Services Using WCF" and one approach described is to take the interface attributed with ServiceContract and use it client side. Just to be clear we're talking about making class like channel.CreateAuthority(authority) and then letting WCF work out what HTTP request to make. You won't want to be doing that.

Anyway I personally wouldn't recommend this to anyone wanting to learn about REST, instead I'd recommend (for now) RESTful Web Services. If however you are using WCF and REST, and feel you already understand REST, then this book will give you some insight into support for REST in WCF.

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone

14 comments:

  1. Hi Colin Jack - first of all - the book is really clear that it isn't REST book and it recommends RESTful Web Services for that very purpose. Publishers pick the title btw :)

    On the HATEOAS issue - yes WCF's support isn't very optimal. That doesn't mean it isn't useful - http://www.intertwingly.net/blog/2008/10/21/Progressive-Disclosure

    ReplyDelete
  2. @Jon
    On it not being a REST book, sure it says it part way through but the title contains the word REST. If its not a REST book then it definitely needs renamed.

    On utter lack of HATEOS support, I agree other RESTful ideas have power even without HATEOS but I was amazed you made no real effort to cover it.

    ReplyDelete
  3. I guess my primary disagreement was that if I bought the book as it is I might consider it a general purpose REST book, which isn't what you were targetting.

    ReplyDelete
  4. So you are saying your primary disagreement is about what I specifically say the book isn't in the foreward?

    ReplyDelete
  5. Well personally I'd have hoped the book would have focussed on all aspects of REST, regardless of how they are supported in WCF.

    Where WCF wasn't inherenty powerful enough I'd have you would have mentioned this and preferably then identifying solutions (extending WCF being one option).

    So in summary I'd have preferred if you started from a REST mindset, rather than a WCF (and related MS technologies) mindset.

    However I realize its difficult to write a book to please everyone, so if you were starting from the WCF mindset then yeah defining it more upfront would have definitely helped.

    ReplyDelete
  6. Hi!

    thx for the review, so i don't have to buy it. i was looking for the same, a book about rest, not wcf.

    i'm very interested in "Seb". could you may provide a link?

    ReplyDelete
  7. @Mike
    Ahh sorry I meant Sebastien Lambla (http://serialseb.blogspot.com/). He actually had to do a lot of messy nasty work to get WCF to be RESTful but he also has his own framework (OpenRasta, http://trac.caffeine-it.com/openrasta).

    ReplyDelete
  8. Colin Jack - you are right that you can't write a book to please everyone.

    I'm ok with that - but your reasoning isn't very sound. You say "..yeah defining it more upfront would have definitely helped."


    If you read the forward - I am very clear that the book isn't about REST in general (why would I write such a book when RESTFul Web Services already covered the topic brilliantly IMO), and not even a book to learn WCF (since other books cover that well). So in my view I defined that very well up front, sorry if you missed that bit.

    Also on the HATEOAS bit - I'd challenge you to tell me how much of the RESTFul Web Services book covers that. Not that much IMO.

    HATEOAS is one of the constraints of REST, but it is't *the* constraint of REST (although Roy finds it required - not everyone agrees with him). Being able to take advantage of GET (caching), and widespread interoperability and simplicity in my book are the more important parts.

    HATEOAS is exteremly important when building a client - and encouraging extensibility and versioning. Don't misunderstand me - important, but just not the most importatnt - at least IMO.

    ReplyDelete
  9. "If you read the forward - I am very clear that the book isn't about REST in general (why would I write such a book when RESTFul Web Services already covered the topic brilliantly IMO), and not even a book to learn WCF (since other books cover that well). So in my view I defined that very well up front, sorry if you missed that bit."

    I read the entire thing, what you say is indeed that your book doesn't cover the "basics of REST" and you then recommended RESTful WS for that.

    By basics I think you mean fundamentals which is fine, you also say that the book is for people who know WCF and REST but want to know about the REST programming model in WCF 3.5.

    Lets say I have indeed read the WCF book you suggest (I've read bits) and have read RESTful WS (I have), do you not think I should expect some serious discussion of connectedness/HATEOS?

    If not then then, regardless of whether you suggest people read RESTful WS, I'd have expected some mention of what aspects of REST you're omitting and why (which to be fair you do, but very late in the book).



    "Also on the HATEOAS bit - I'd challenge you to tell me how much of the RESTFul Web Services book covers that. Not that much IMO."

    Yup agreed, and I think thats one of weaknesses of that book too...but it does spend some time discussing connectedness.



    "HATEOAS is one of the constraints of REST, but it is't *the* constraint of REST (although Roy finds it required - not everyone agrees with him). Being able to take advantage of GET (caching), and widespread interoperability and simplicity in my book are the more important parts."

    I didn't say it was *the* constraint and I agree, I love this idea of levels of REST (http://www.crummy.com/writing/speaking/2008-QCon/act3.html).

    And to be honest, if you do think its not an important part of REST, then thats exactly what I would have expected to find in your book.

    Correct me if I'm wrong but isn't the main reason you omitted it because WCF doesn't support it very well?

    ReplyDelete
  10. Yes - WCF has little support for HATEOAS - and yes that is the main reason why it isn't in the book. Although - lots of the book is about creating hyperlinks in resources, which is certainly part of HATEOAS (without the hyperlinks - clients can't follow them).

    WCF has little support for it - and AFAIK most frameworks are pretty much the same. Dynamic languages are probably the way to go here - so once C# 4.0 comes out there will be a mainstream way to do this in .NET.

    ReplyDelete
  11. @Jon
    Even on linking I'm not entirely pleased. What you really want is to be able to have a collection of List< Link< OrderContract>> on a CustomerContract and have WCF automatically use the information it has about OrderContract to add the links.

    Take one of the examples of linking Subbu's excellent InfoQ article (http://www.infoq.com/articles/subbu-allamaraju-rest).

    I want WCF to build the link for me. The href is easy for WCF to generate because it already knows the URL's you use for orders, assuming you've specified a handler that's solely focussed on Order (your class attributed with ServiceContract).

    The type is also possible to add assuming the OrderContract class is associated with a media type (though you'd have to vary it based on the type of representation e.g. adding "+xml" here).

    Anyhow it all sounds sensible but as Seb found out when implementing our REST framework "on top of" WCF its all way more difficult than it should be.

    ReplyDelete
  12. Seems like you have more against my book just because it sticks to the basics of WCF (which is on purpose), and against WCF in general.

    When I build RESTful services using WCF I do similar things that you are describing, but I have a moral problem with book authors who write books all about their own personal frameworks.

    ReplyDelete
  13. Yeah I want a book with REST in the title to focus on all aspects of REST, or to clearly state why this is not happening (e.g. because WCF has weak support in some areas).

    Personally though I've got almost the opposite attitude on framework, if your frameworks make up for some of the big issues in the REST support of WCF then as a reader I definitely want to hear about the problems you solved and why its important.

    Even better open source your personal frameworks to go along with the book.

    ReplyDelete
  14. @mike
    Sorry for slow reply, Seb is the author of OpenRasta:

    http://serialseb.blogspot.com/

    ReplyDelete