by Andrew C. Oliver

Web services are dead โ€” long live REST

opinion
Jan 24, 20135 mins
Jakarta EEJavaWeb Development

How REST plus JSON over HTTP/HTTPS won the race on interoperability

Remember the heyday of Web services, when we were always just one specification away from perfect interoperability? Ultimately, that towering stack of protocols collapsed under its own weight. SOAP and XML generally are ridiculously verbose protocols that began with a commitment to simplicity and gave way to mind-numbing levels of complexity. Add to that the service repository mess: UDDI died an ignominious death, and OASISโ€™s S-RAMP committee canโ€™t even create a website that isnโ€™t all broken links.

Interoperability Nirvana remains out of reach. What do we have instead? We have the registry called โ€œthe freaking Internet.โ€ Services are registered as URL handlers, and we execute against them. The XML transmission format was replaced by the format that your browser and mobile devices all learned to speak: JavaScript Object Notation. REST plus JSON over HTTP/HTTPS is the new Web services โ€” strangely, itโ€™s more interoperable without an explicit specification. Instead we make it work like the Internet, and DNS is your service registry.

[ Also on InfoWorld: 9 app dev projects you should cancel in 2013. | Download InfoWorldโ€™s PDF of tips and trends programmers need to know in our Developersโ€™ Survival Guide. | Keep up with the latest developer news with InfoWorldโ€™s Developer World newsletter. ]

We use JQuery/JavaScript/JSON for our UIs nowadays. We can even use Node.js for our business logic. Databases like Couchbase 2.0 and MongoDB speak JavaScript and JSON (or a direct derivative) natively. The beauty of this as an architecture is that we can drop entire layers of object binding and data transformation from our code.

Brought to you by the Internet

What does this look like? Consider your Order/Line items example.

Save or update the order:

POST http://infoworld.com/example/Order/123

{

ย ย ย "firstName": "Andrew",

ย ย ย "middle": "C",

ย ย ย "lastName": "Oliver",

ย ย ย "address": {

ย ย ย ย ย ย ย "streetAddress": "345 West Main St, Suite 201",

ย ย ย ย ย ย ย "city": "Durham",

ย ย ย ย ย ย ย "state": "NC",

ย ย ย ย ย ย ย "postalCode": 27701

ย ย ย },

ย ย ย "LineItems": {

ย ย ย ย ย ย ย {

ย ย ย ย ย ย ย ย ย ย ย "type": "widget",

ย ย ย ย ย ย ย ย ย ย ย "sku": "123-456"

ย ย ย ย ย ย ย },

ย ย ย ย ย ย ย {

ย ย ย ย ย ย ย ย ย ย ย "type": "widget",

ย ย ย ย ย ย ย ย ย ย ย "number": "452-123"

ย ย ย ย ย ย ย }

ย ย ย }

}

Replace the line items of the order:

PUT http://infoworld/example/Order/123/LineItems

{

ย ย ย ย ย ย ย {

ย ย ย ย ย ย ย ย ย ย ย "type": "widgetTypeA",

ย ย ย ย ย ย ย ย ย ย ย "sku": "123-456"

ย ย ย ย ย ย ย },

ย ย ย ย ย ย ย {

ย ย ย ย ย ย ย ย ย ย ย "type": "widgetTypeB",

ย ย ย ย ย ย ย ย ย ย ย "number": "452-123"

ย ย ย ย ย ย ย }

ย ย ย }

Delete the order:

DELETE http://infoworld.com/example/Order/123

Get the order:

GET http://infoworld/example/Order/123

Security in a RESTful world

As Oracle will tell you, security isnโ€™t really important, and the best way to handle it is by sticking your head in the sand and making people wonder if you are the corporate equivalent to Grandpa from โ€œThe Simpsons.โ€ However, if youโ€™re one of those young whippersnappers who care about preventing other people from stealing your stuff, youโ€™ll want to secure those RESTful Web services. Security is simple with RESTful Web services. Since complexity tends to result in complex breakages, this is a good thing โ€ฆ mostly.

For RESTful Web services you generally use HTTPS and basic authentication.

Not quite nirvana

I admit that Iโ€™ve always had a nearly irrational hatred for XML that comes from having to type angle brackets; on an American keyboard, itโ€™s a recipe for a hand cramp if youโ€™re a touch-typist. That said, DNS tells us where the ordering system is. It isnโ€™t particularly good for telling us that all orders go under โ€œOrderโ€ and not โ€œorderโ€ or โ€œOrdersโ€ or โ€œorders.โ€

We can have a corporate convention and publish documentation, but this isnโ€™t exactly an Internet-wide phenomenon. You can use WSDLs โ€” or now their lighter-weight (but still big) wall of XML cousins, WADLs โ€” but it quickly leads us down the path of โ€œwhere is my service registry?โ€ to store the WADLs. There also isnโ€™t much of a convention for โ€œwhereโ€ to get the WADL relative to the service. Nothing good will come from shoving more stuff into DNS txt records, and if we end up with a WADL for DNS over HTTP, then happy hipsters will bring about the meta-apocalypse.

When it comes to security, the basic authenticationโ€™s point-to-point may not be adequate to the task. Systems donโ€™t just do things for the right client; sometimes they facilitate requests on behalf of that client on other systems. In a robust SOA environment, these kinds of โ€œon behalf ofโ€ activities and other kinds of nontrivial security arrangements are more commonplace.

Choose both?

It is possible with many modern frameworks to deploy a service with both JSON and XML endpoints. Itโ€™s somewhat difficult, but not impossible, to be RESTful and SOAP-y at the same time. Increasingly, companies have to expose services as JSON for their myriad of devices. Some companies deploy front ends as REST-y JSON, then have another tier of XML sauce.

All this begs a question: In an AJAX-y world with mobile clients, what really is a front-end service instead of back end? Isnโ€™t the JavaScript-like HTML page just a client? Frequently these โ€œfront-end servicesโ€ devolve into an overblown proxy or remoting version of the GoF bridge pattern. In other words, itโ€™s needless bloat and object transformation.

A few years ago all remotely accessible services were by default deployed as SOAP Web services because that was assumed to be the future. The AJAX mobile revolution changed all of that. Now, because you are probably developing services for both Web and mobile devices, and you may be developing services for your wider enterprise or the Internet, why not just do REST and forget the SOAP monster?

This article, โ€œWeb services are dead โ€” long live REST,โ€ was originally published at InfoWorld.com. Keep up on the latest developments in application development at InfoWorld.com. For the latest business technology news, follow InfoWorld.com on Twitter.