How can i implement both restful and Soap together?
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.
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.