Saturday, November 03, 2007

Why RESTful Web Services Matter: Part 3

In Part 2, I talked about how the RESTful uniform interface facilitates learning and supporting RESTful web services. Today, I will talk about other benefits that are just as important.

In RESTful web services, the HTTP operations GET and HEAD are required to be safe. In other words, performing them any number of times must not affect server state. They are meant to be used for querying purposes only.

Additionally, the HTTP operations GET, HEAD, PUT and DELETE are required to be idempotent. What does that mean? Performing an idempotent operation once or more than once must have exactly the same effect. For example, if the contact manager web services had an idempotent DELETE operation, then if you call DELETE on http://www.contactzmanager.com/contact/35 to delete the contact with ID 35, and then a few seconds later repeat the call again, the server should be fine with that and not complain. Of course, the contact will only be deleted once.

Finally, all basic HTTP operations in RESTful web services, including POST, must be implemented in a way that keeps the server as stateless as possible.

What are the benefits we reap of having safety, idempotence, and statelessness in RESTful web services?

  • Reliability: Since networks are unreliable, connections sometimes break and you cannot guarentee that your requests went through. However, because GET, HEAD, PUT, and DELETE requests are safe and idempotent, you can repeat multiple times as needed.

  • Scalability: Stateless servers can be scaled very easily by adding as many servers as needed to handle the load.


On the other hand, operations in SOAP Web Services are often completely tunneled through POST requests, usually missing out on the benefits of safety and idempotence.

Stay tuned for a discussion about the advantages and disadvantages of having a standard message format for SOAP and no particular message format for RESTful web services.

Go to Part 4 here.

No comments: