views:

128

answers:

5

I'm creating a general purpose web service that is likely to have a number of different clients, some of which I cannot anticipate at this time.

I already have a nice Java Services API and am looking to provide a web services facade on top of that.

There are great arguments on both sides of the SOAP vs REST debate and it leaves me wondering if there is an easy way to offer both? Not necessarily both at the same time for the same deployment (although that might be nice)...but rather to offer a choice to customers.

+2  A: 

Yes, you can offer both (and I'd recommend to do it). You can make the decision of which format the response should be in based on either the HTTP Accept header (application/soap+xml vs. application/json) or a custom query parameter (eg http://example.com/myapi?fmt=soap vs. http://example.com/myapi?fmt=json). In any case, you need to have clear default fallback value, if the client has not specified explicitly the desired format for the response.

You might also consider adding REST/POX response format as well, with Atom+optional extensions as your response container. (application/atom+xml and http://example.com/myapi?fmt=atom for the two methods above)

Franci Penov
I'm still a web services newbie, so can I ask for some clarification? Are you saying that the you can offer SOAP/XML, SOAP/JSON, REST/JSOM, and REST/POX all at the same time by using the the HTTP accept header as a way to differentiate what the caller wants back? How do you implement this? What tools and frameworks support this?
HDave
Yes, you understood it right. It's all just a matter of proper serialization of the web-service response to a format that the client understands. (Btw, there's no such thing as SOAP/JSON. :-))
Franci Penov
I don't know if/what Java web-services frameworks there are and which support response format switching, but I'd imagine any modern web-services framework ought to support it. If you give some details which particular framework you are using, I am sure people will be able to tell you exactly how to do it in it.
Franci Penov
I'm not using one yet, just trying to figure out what are important criteria in selecting one. I've had CXF recommended to me by others. Can it support this?
HDave
I have not used it, but according to http://cxf.apache.org CXF supports both SOAP and REST/HTTP bindings and XML, JSON and FastInforset message formats.
Franci Penov
A: 

I'd stick with the simple REST solution. Amazon has both REST and SOAP apis for the same services and the REST services are used 85% of the time so if you don't have a specific need for SOAP then I wouldn't implement it.

BrennaSoft
-1: that's not what he asked.
John Saunders
Its a customer requirement as this system will be part of a larger SOA strategy.
HDave
+1  A: 

Briefly, a single WCF service can offer multiple endpoints for the same service contract. One can be REST, one can be SOAP/XML, one can be TCP/IP+binary.

John Saunders
Does this apply specifically to WCF? I didn't mention it before because I didn't think it was supposed to matter, but the app is implemented as a Java servlet.
HDave
Yes, this is specifically WCF. If your platform is Java, you should add that to your tags.
John Saunders
+1  A: 

No, there isn't. SOAP and REST are such different architectures that any framework that proports to make it easy to do both is probably doing a bad job at one of them.

While it's easy to get a set of functions or methods to a WSDL file, SOAP endpoint and so on that's because functions, and SOAP both do basically the same thing with no constraints on what happens. A caller sets up a function call with a number of parameters, fires it and (usually) waits for a response or exception.

Making HTTP endpoints for each method is what some people think is enough to make a RESTful endpoint, but it's not. However, making such HTTP endpoints may still make sense to you, in which case you should go ahead and find a framework that provides this.

The reason my answer starts with "No, there isn't" is because in order to make a REST interface, it's not enough to publish HTTP endpoints, you have to do a lot more work:

  • finding media types to reuse
  • finding link relations to reuse
  • designing your own media types
  • defining your own link relations

And there's no framework in the world that will take an arbitrary list of function signatures and do those four things for you. Frameworks allow you to leverage more of HTTP than SOAP does (e.g. OAuth, OpenID, caching, idempotency), but they don't take you all the way to REST.

mogsie
+1  A: 

I'm not really keen on soap web services but googling around i've found that Axis 2 framework from apache not only provides SOAP 1.1 and SOAP 1.2 but also REST/POX with the same business logic implementation. YOu can see more information:

http://ws.apache.org/axis2/

Fgblanch