PUT | POST |
---|---|
The PUT method is a call when you have to modify a single resource, which is part of resource collection. | POST method is a call when you have to add a child resource under resource collection. |
The PUT method is idempotent | POST method is not idempotent |
PUT for UPDATE operations. | POST for CREATE operations. |
If the PUT request is used more than one time, the results will remain the same. | If a POST request is used multiple times, the results will be different. |
PUT works as specific. | POST work as abstract. |
PUT
for GET
. GET
operations should only have view rights, while PUT
resource is used for updating a data.
AJAX | REST |
---|---|
In Ajax, the request are sent to the server by using XMLHttpRequest objects. The response is used by the JavaScript code to dynamically alter the current page. | REST have a URL structure and a request/response pattern the revolve around the use of resources. |
Ajax is a set of technology; it is a technique of dynamically updating parts of UI without having to reload the page. | REST is a type of software architecture and a method for users to request data or information from servers. |
Ajax eliminates the interaction between the customer and server asynchronously. | REST requires the interaction between the customer and server. |
JAX-RS
provided annotations for implementing web resources.POJOs
that are annotated either with @Path or have at least one method annotated with @Path
, @GET
, @POST
, @DELETE
, @PUT
, etc.import javax.ws.rs.Path;
/**
* InterviewBitService is a root resource class that is exposed at 'resource_service' path
*/
@Path('resource_service')
public class InterviewBitService {
// Defined methods
}
SOAP | REST |
---|---|
SOAP is a protocol through which two computer communicates by sharing XML document. | Rest is a service architecture and design for network-based software architectures. |
SOAP permits only XML | REST supports many different data formats |
SOAP based reads cannot be cached | REST reads can be cached |
SOAP is like custom desktop application, closely connected to the server | A REST client is more like a browser; it knows how to standardized methods and an application has to fit inside it |
SOAP is slower than REST | REST is faster than SOAP |
It runs on HTTP but envelopes the message | It uses the HTTP headers to hold meta information |
REST | Web Socket |
---|---|
REST follows stateless architecture, meaning it won’t store any session-based data. | Web Socket APIs follow the stateful protocol as it necessitates session-based data storage. |
The mode of communication is uni-directional. At a time, only the server or the client will communicate. | The communication is bi-directional, communication can be done by both client or server at a time. |
REST is based on the Request-Response Model. | Web Socket follows the full-duplex model. |
Every request will have sections like header, title, body, URL, etc. | Web sockets do not have any overhead and hence suited for real-time communication. |
For every HTTP request, a new TCP connection is set up. | There will be only one TCP connection and then the client and server can start communicating. |
REST web services support both vertical and horizontal scaling. | Web socket-based services only support vertical scaling. |
REST depends on HTTP methods to get the response. | Web Sockets depend on the IP address and port number of the system to get a response. |
Communication is slower here. | Message transmission happens very faster than REST API. |
Memory/Buffers are not needed to store data here. | Memory is required to store data. |
@RequestMapping
annotation.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
GET
and DELETE
methods. There can be some client libraries that do not support the payload with these two methods. It’s also possible that some servers may just ignore the body of GET
and DELETE
methods. It’s better not to include payload with these two methods. @Controller | @RestController |
---|---|
Mostly used traditional Spring MVC service. | Represents RESTful web service in Spring. |
It is mostly used in Spring MVC service where model data needs to rendered using view. | It is used in case of RESTful web service that returns object values bound to response body. |
If response values need to be converted through HttpMessageConverters and sent via response object, extra annotation @ResponseBody needs to be used on the class or the method handlers. |
The default behavior of the @RestController needs to be written on the response body because it is the combination of @Controller and @ResponseBody . |
@Controller provides control and flexibility over how the response needs to be sent. |
@RestController annotation has no such flexibility and writes all the results to the response body. |
@PathVariable
annotation. Multiple @PathVariable
can be used in the same method. In resource creation, the path variable plays a critical role. Spring MVC provides URL customization support for retrieval of data through the use of @PathVariable
.