Monday, 26 February 2018

SOAP Vs Rest Definitions (also produces consumes)

SOAP Web Services: Runs on range of protocols such as FTP, HTTP, SMTP, Post office protocol 3(POP3) to carry documents and uses XML technology for sending data.
has WSDL file. Only XML can be used,SOAP is based on the contract

Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol almost all the time. REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services.
Supports multiple technologies for data transfer such as text, xml, json, image etc.

Accept and Content-Type Headers in HTTP Request?
These are important headers in Restful web services.
Accept headers tells web service what kind of response client is accepting, so if a web service is capable of sending response in XML and JSON format and client sends Accept header as “application/xml” then XML response will be sent. For Accept header “application/json”, server will send the JSON response.

The @Consumes annotation is used to specify which MIME media types of representations a resource can accept, or consume, from the client.
The @Produces annotation is used to specify the MIME media types or representations a resource can produce and send back to the client.

Content-Type header is used to tell server what is the format of data being sent in the request. If Content-Type header is “application/xml” then server will try to parse it as XML data. This header is useful in HTTP Post and Put requests.

There are two major implementations of JAX-RS API.

Jersey: Jersey is the reference implementation provided by Sun. For using Jersey as our JAX-RS implementation, all we need to configure its servlet in web.xml and add required dependencies. Note that JAX-RS API is part of JDK not Jersey, so we have to add its dependency jars in our application.
RESTEasy: RESTEasy is the JBoss project that provides JAX-RS implementation.

For setting HTTP status code other than 200, we have to use javax.ws.rs.core.Response class for response.

https://www.journaldev.com/9193/web-services-interview-questions-soap-restful#comment-42335

No comments: