REST API Design Rulebook By Mark Masse

Posted February 2, 2012 at 9:57 AM by Ben Nadel

Tags: Books

Over the weekend, I read The REST API Design Rulebook by Mark Masse. I absolutely loved this book! In a world where so many computer science questions are answered with, "It depends," or, "there's no 'right' answer," Masse comes through with a book that says, No, these are the rules - this is how you design a RESTful API. This book explores all aspects of RESTful API design through an exhaustive set of concise, unambiguous rules that challenge you to think carefully and deeply about your choices.


 
 
 

 
REST API Design Rulebook by Mark Masse, reviewed by Ben Nadel.  
 
 
 

While I absolutely love the way this book is presented, I don't necessarily see myself adopting all of the concepts Masse describes. For example, the use of WRML - his Web Resource Modeling Language - seems like a little too much effort to me, at least for the moment; I suspect that I can still get a tremendous amount of value from my RESTful APIs without having to add Schema and Format components to my HTTP headers.

But that's OK. As much as this book is about Rules, Masse fully understands that his rules may be challenged, or even rejected:

This book presents a set of REST API design rules that aim to provide clear and concise answers to the nagging questions listed above. The rules are here to help you design REST APIs with consistency that can be leveraged by the clients that use them. These rules can be followed as a complete set or a la carte. You may contest the rules, but I believe that each one warrants careful consideration. (Page 23 of 186)

After this disclaimer, Masse goes on to bring a level of clarity and consciousness to all aspects of RESTful API design. This includes, but is not limited to how your domains and sub-domains should be chosen; how your URIs (Universal Resource Identifiers) should be structured; what HTTP verbs (ex. PUT, POST, GET, DELETE) should be used for which types of resources and action; how to choose the correct HTTP Status Code response; how to define your response body (and when to exclude a response body); how to link to related content and actions (within your response); and, how to chose the correct Content-Type header values.

Take that last one, as an example - choosing the correct the Content-Type header value. When I return content in a request, I more or less use the content-types that I see other people using. In the past, when I've returned JSON content, I've gone with any one of the following:

  • text/json
  • application/json
  • application/x-json

I don't actually know which one is right - I just copy others; but, as Masse explains, there doesn't have to be any guesswork involved. The Internet Assigned Numbers Authority (IANA) aggregates the standards for content type selection. For JSON, the standard is:

application/json

The book is so rule-driven that it's hard to talk about it without actually just repeating the rules that Masse has outlined. All I can really say is that I truly enjoyed this book. It has definitely made me question a lot of the choices that I've made in RESTful API design; and, it has me wanting to think more deeply and carefully about my choices going forward. I would say this book is a must-read for any server-side developers, especially those who are even thinking about taking on RESTful API deployment.



Reader Comments

Feb 2, 2012 at 10:12 AM // reply »
11,246 Comments

I forgot to include a link to the Intenet Assigned Numbers Authority:

http://www.iana.org/assignments/media-types/index.html

It's seems pretty comprehensive. In the book Masse points out that most RESTful APIs will deal with content-types that fall under the primary category:

application/*


Feb 3, 2012 at 12:15 PM // reply »
1 Comments

As far as I can tell, WRML is not a standard but just something the author came up with. Seems pretty convoluted to me.

Have you read RESTful Web Services Cookbook (http://shop.oreilly.com/product/9780596801694.do) seems like a more in-depth resource. I enjoyed reading it, and it seemed to me to have the same level of "this is what you're supposed to do".


Feb 3, 2012 at 1:10 PM // reply »
11,246 Comments

@Jordan,

Yeah, WRML was created by Mark Masse (author of the book). I also found it to be a bit convoluted. I suppose it is intended to allow the Client to be able to programmaticaly respond to changes in the API (as opposed to versioning the API or hardcoding values in the client code)... but, it feels a little bit to me like an unnecessary step that will end up making the client code more complex than is necessary.

I haven't seen that Cookbook, I'll check it out! Thanks for the link!


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools