2

Does a RESTful web service (e.g. in a JAX-RS implementation) support both contract-first (top-down) approach and contract-last (bottom-up) approach?

Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • Please be more specific. What do you think would the results of these approaches be in a JAX-RS application? –  Oct 26 '13 at 13:30
  • If both approaches are supported by soap(JAX-WS) than why not RESTful? –  Oct 26 '13 at 17:53
  • I know restful support contract-last but does it support contract-first? If not y so? Bcos contract-first give holistic management which is much needed today's business –  Oct 26 '13 at 17:58

1 Answers1

3

Do RESTful web services support both contract-first and contract-last approaches?

It depends on what tools/frameworks you use.

What you are talking about applies to a SOAP web service and its accompanying WSDL.

A WSDL describes what a web service expects as input and what should a client expect as output. It defines the contract to be followed in order for both parties to communicate with each other. You can obtain the WSDL by doing contract-first or contract-last and you can later use this WSDL to generate code for a client stub or a service skeleton.

But doing REST isn't the same as doing SOAP. Processes that worked for SOAP (a protocol) can't necessarily be applied to REST (an architectural style) just because we are familiar with them.

Unlike SOAP that exposes methods and method signatures, REST exposes resources. An understanding of the media types used in the exchange of those resources is all a REST client needs in order to communicate with a REST web service. There is no need for a separate document to describe the resources.

Because of the HATEOAS principle, REST clients are more dynamic and can adapt to other services that communicate using the same media types. Exposing static service description documents would be limiting for a REST service.

Having said that, there are REST tools that do expose a description document, for example Jersey who exposes a WADL (contract-last). I'm sure you can use the published WADL to build client stubs and I don't see a reason why you couldn't write the WADL by hand (contract-first) and use it to generate stubs and skeletons. But as I said, that might not be the best solution for REST.

Here are some posts you might want to read to form an opinion if contract-last or contract-first approaches make sense in REST:

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61
  • Good one, but, Will u please give me name of any tool/framework through which i can implement RESTful web service using contract-first approach. I dont think RESTful support contract-first in anyway!..Thanks for reply –  Nov 06 '13 at 09:10
  • @Siraj Chaudhary: The only tools I'm aware of (have no idea how stable they are or how many features they have because I only know about them, I didn't actually use them) are [WADL2Java](https://wadl.java.net/) which [I think is what CXF uses](http://cxf.apache.org/docs/jaxrs-services-description.html#JAXRSServicesDescription-WADLfirstDevelopment), and a more generic tool called [rest-api-code-gen](http://code.google.com/p/rest-api-code-gen/). – Bogdan Nov 06 '13 at 17:23
  • This information is useful. It means we can write contract first web service with RESTful as well. Thanks @Bogdan –  Nov 11 '13 at 12:47