What is HATEOAS ?
HATEOAS is acronym for Hypermedia As The Engine Of Application State.
Its about using hypermedia and hyperlinks for providing complex information through the service.
Hyperlinks allow us to reference and aggregate additional data without bloating the service response.
For example, if your service returns different products, then rather than sending all the products in the response, it can send 5 or 10 products and then provide a link that would request for the next set of products.
This makes the response lite and the service flexible.
When to use REST and when to use SOAP ?
Use SOAP, if :
1) The service provider and client/consumer need to follow a formal contract. The format is provided in the form of a WSDL file.
2) SOAP provides additional features for stateful operations.
3) Security : SOAP provides additional security by using WS-Security.
Use REST for
1) Stateless operations
2) When the information can be cached. Caching can be done by adding a gateway cache or reverse proxy infront of it.Some frameworks provide their own reverse proxies, but a very powerful, open-source one is Varnish.
When a safe method is used on a resource URL, the reverse proxy should cache the response that is returned from your API. It will then use this cached response to answers all subsequent requests for the same resource before they hit your API. When an unsafe method is used on a resource URL, the cache ignores it and passes it to the API. The API is responsible for making sure that the cached resource is invalidated.
HTTP has an unofficial PURGE method that is used for purging caches. When an API receives a call with an unsafe method on a resource, it should fire a PURGE request on that resource so that the reverse proxy knows that the cached resource should be expired.
3) quick development : when you need the service developer and ready in quick time, rest is the way to go
Difference between a restful webservice on HTTP and a HTTP servlet
REST is an architectural style of creating webservice. HttpServlets can be a method of implementing Restful webservices.
Jersey is implemented on top of servlets.
Can my web browser be a client to RESTful web service? If yes then how will you generate DELETE request from web browser?
Yes, browser can be used as a client. You can make GET & POST calls only.
HTML forms (up to HTML version 4 and XHTML 1) only support GET and POST as HTTP request methods. A workaround for this is to tunnel other methods through POST by using a hidden form field which is read by the server and the request dispatched accordingly.
However, GET, POST, PUT and DELETE are supported by the implementations of XMLHttpRequest (i.e. AJAX calls) in all the major web browsers (IE, Firefox, Safari, Chrome, Opera).
How will you handle synchronization issues when multiple clients try to consume web service simultaneously?
Similar to a servlet implemnetation, web service method implementation must take care of all synchronization issues. You can do this using synchronization.
© 2015 – 2017, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post