Effective Naming Strategies for RESTful Web Services
By Lukas Stewart
One of the major shortcomings of RESTful web service design is the historic lack of any strong technology that can be used to effectively describe the service contract interface between the server and the client. RESTful APIs are flexible, sensible and provide for a great deal of loose coupling, but if an application architect is looking for an effective way to describe the RESTful API in a manner similar to the way WSDL describes traditional SOAP based web services, well the architect is sadly out of luck.
Fortunately, the description languages are catching up with the popularity of REST, and WSDL 2.0 and WADL are two technologies that are filling the RESTful need. Of course, these specifications are not perfect, as their ability to describe JSON strings and complex attributes is still lacking, but nevertheless, progress is being made.
One caveat to using these technologies, especially if software engineers are hoping to use code generators to create WADL and WSDL files is the fact that resource elements in a RESTful URL need to be separated with constants. It's actually a good idea in general, as it makes URLs more meaningful and easier to read. But new standards are making the use of interjected constants less about what's good, and more about what's required.
When you see an example, it's fairly easy to comprehend. Take a look at the following URL that might be used for a product rating service:
In this example, you can see quite clearly that a plunger is being given a five out of five product rating. But the URL is not separated with constants, which causes problems with the description languages. Fortunately, solving the problem is easy, as you can see from the following, corrected URL:
The words product and rating are constants in the URL, and assign meaning to the corresponding resource values. As you can see, it's not a big change in terms of URL design, but it is significant, as it will make your RESTful APIs more compatible with the various description languages on the market today, and in turn, clients will have fewer problems when interacting with them.
06 Mar 2013
Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.