rest with json vs soap with xml

Download Rest With Json Vs Soap With Xml

If you can't read please download the document

Upload: kaniska-mandal

Post on 20-May-2015

9.416 views

Category:

Documents


2 download

TRANSCRIPT

  • 1. The whole idea of Web Service is simplifying data access as much as possible withoutcompromising security of services. Thats where REST outplays SOAP. The systemshould be designed as Resources and should be identified by URLs. Then the servicesshould be accessed by a small set of remote methods describing the actions to beperformed on the resource. This is how REST smoothly fits into such architecture as anatural choice when services are stateless and interpreted as Resource URL.For example, the best way make a POST request using REST :http://127.0.0.1:8080/myrestservices/loanservice/acceptLoan with the JSON / XML as thebody of the request.RESTful styles perfectly suits for AJAX Tools where multiple web service calls might beperformed very frequently. SOAP suffers from huge overhead of Headers and heavy XMLpayloads even for a simple service call.REST should be the used specially where Bandwidth is limited such as PDA and MobileDevices.Particularly REST can be easily implemented into existing system of URL oriented staticresources without much refactoring or change in existing system architecture.Since SOAP needs to carry lots of additional information like Quality ofService, WS Transaction, Security etc. its suitable for integrating complex heterogeneoussystems and specific cases where a service call tends to needs to perform multipleoperations in a blocking mode and needs to communicate signals back and forth betweenservice provider and consumer before performing a WS-Transaction.Otherwise, its always better to simple use REST binding for web service and intercept theservice call to ensure security and QOS and then perform the actual transaction withoutoverloading the headers.Proxy Servers can be setup to cache stateless services effectively.

2. Accessing REST services normally wont require any specialized webservice clientsbecause REST relies on HTTP methods so that any Browser can makethe RESTified service calls.Now why should we use JSON as the defacto standard for data exchange both for makinga REST service call and communicating between services.JSON seamlessly integrates with JavaScript and Python as a simple Map Data Structurewhereas XML always required an additional syntax to define its grammer and it has ahierarchical complex data structure.User does not need to keep on creating new tags or attributes to represent new datain JSON as user can simply represent them using Key-Value pairs. In JSON, a Value canbe represented as a nested key-value structure recursively.JSON support arrays {Orders:["Order":"[Id:123]...."]} and is more elegant and compact. Itdoes not suffer from the - how to distinguish an attribute from a child elementproblem.JSON is fully optimized for exchanging lightweight data i.e. its not suitable for exchangingSounds / Images / Binary executable .XML is more suitable for heavy-weight payloads which is not recommended for WebService.But again handling XML requires specialized knowledge whereas JSON code can beeither converted into simple JSONObject beans that can simply be looked up for childbeans.So JSON is best for exchanging Data, where as XML is suitable for exchangingDocuments.Any Web Service Provider should adopt REST and JSON for keeping the services highlyscalable and making fast service calls and providing best user experience over web. 3. References :JSON vs XML code comparison : http://www.25hoursaday.com/weblog/PermaLink.aspx?guid=39842a17-781a-45c8-ade5-58286909226bJSON Wrapper : http://www.jspon.org/