Software developers demanding resource based, RESTful APIs
By Jason Tee
Well seasoned enterprise architects know that there is no silver bullet in the world of IT, and no single solution will ever meet every requirement criteria to the tee, but when it comes to web service development, a REST based approach is becoming more and more popular. REST may not be the best approach for every situation, but it does have enough virtues to put it on the short list for any organizations that is comparing the various different approaches to web service development . And the fact is, a REST based approach can be effective in even the most challenging corner-cases. The key is that developers simply have to use REST the right way.
The effective application of RESTful techniques
Needless to say, using a REST based approach for developing a distributed architecture effectively becomes a whole lot easier when there is a proven and effective structure within which applications can be built. In the world of distributed computing, if you want to understand RESTful development, you scour the globe to find an expert. In this case, TheServerSide caught up with Jerome Louvel (@jlouvel), coauthor of Restlet in Action and the creator of the Restlet framework. Lovell shared several insightful tips for getting the most out of RESTful web development.
One issue web developers often raise is how to get things done with REST when it comes to handling complex, real world transactions that involve multiple resources whose interactions need to be coordinated. Louvel addresses the topic of e-commerce by framing it as a simple use case with a straightforward solution. For example, to make a traditionally developed online shopping application into a RESTful experience, an architect simply needs to break down the associated business transactions into all of their underlying components.
In a transactional, online e-commerce type of system, people need to be able to browse products, select products, view and edit their cart, enter payment and shipping information and then make a final decision to pay. At any point up to the point where the user completes their checkout, users need to be able to navigate back to a previous step. From a pure API standpoint, this means mapping all the important parts of the transaction into resources via URIs. At the end, the transaction is completed by sending a final HTTP request that coordinates the state of each of the resources involved in the transaction.“It’s just viewing your transaction as a set of one or multiple resources depending on the complexity of your business processes. Technically, nothing prevents you from doing that. It’s just not trying to map what you’re used to doing with RPC or putting too much context in one request,” says Louvel.
Easing into a resource based approach to APIs
Designing a RESTful API is often about unlearning what you knew before. Developers run into problems when they try to overlay their previous knowledge and understanding of distributed computing with RPCs. That’s when developers finds themselves creating more problems than they fix. Louvel’s advice is not to take the usual, traditional approach when developing RESTful APIs. Forget what you learned from the service-oriented, RPC based world. Then, you’ll discover that you are working without limitations and you can really start to solve your business problems. Furthermore, the modularity involved in developing a RESTful architecture means developers have smaller, more agile parts that provide greater flexibility when designing solutions that really work.
The main takeaway Louvel has for Java developers is this: apply as many principle from the tenants of RESTful development and design as possible, but at the same time, use only as much as is needed. See everything as a resource. Use calls from the HTTP protocol, especially GETs, PUTs, POSTs and DELETEs to effectively create and update your resources. Eventually, approaching the problem domain in a RESTful manner becomes second hand. By applying these foundational concepts, developers get a lot of built-in features that are common to the world-wide-web such as caching and automatic compression for free.
And once the development team has got the basics down, kick it up a notch and try to see every problem as having a RESTful solution. Says Louvel, “try to use hypermedia as much as possible to become the engine of your application. This is a principle that is difficult to apply and people are still trying to find the best way to do that.”
03 May 2013