tags:

views:

125

answers:

3

How can i implement both restful and Soap together?

A: 

REST and SOAP are mutually exclusive concepts. You can't.

Wahnfrieden
You can't do http based REST over SOAP, but you could define a new uniform interface using SOAP based interfaces. There is nothing to stop SOAP messages from being hypermedia. The only part I'm not sure about is how standard media types fit in. The SOAP envelope could become the alternative to http headers for the purpose of describing the message.Unfortunately, I don't think the OP is really asking can he do RESTFul SOAP, I think he is asking if he can expose an interface which is both SOAPy and RESTful at the same time, which I believe is NO. WCF seems to believe differently though.
Darrel Miller
+1  A: 

Given an arbitrary service there is nothing stopping you exposing both REST and SOAP interfaces to it. However, the nature of the service may lend itself to one method of access more than the other.

Andy
+1  A: 

You can't implement a single API which conforms to both REST and SOAP.

However, it is possible to create a system which exposes a RESTful API and a SOAP API with equivalent functionality.

In order to do so, the underlying implementation of the system should be independent of both APIs. If, for example, you were implementing your system with Java, the underlying implementation and each API should all be in independent packages. If Python, independent modules. Etc.

Ideally, if you had infinite time, each API would be fully designed to conform to the underlying paradigms of their architecture styles: the RESTful API would be properly oriented around resources and transfers of representations of their state, and the SOAP API would be properly oriented around procedures and their parameters and return values.

However, in order to save some time, it's possible to model a SOAP API after a REST API, by simply combining the resource names with the HTTP methods. The result is a kind of a REST-via-SOAP hybrid.

For example, if your REST API has a resource named Mailboxes, which supports GET, POST, PUT, and DELETE, and accepts and returns representations of type application/json, you could model the resource and its methods by creating the following SOAP methods:

  • get_mailboxes(url, options) returns jsonDoc
  • post_mailboxes(url, options, jsonDoc) returns jsonDoc
  • put_mailboxes(url, options, jsonDoc) returns jsonDoc
  • delete_mailboxes(url, options) returns nothing

I apologize if my notation is incorrect, I'm not all that familiar with SOAP.

Avi Flax