Tuesday 25 February 2020

6 years exp java interview preparation_SpringRestApi

Rest Full services:
@RestController =@Controller+@ResponseBody

REST is used to build Web services that are lightweight, maintainable, and scalable in nature. A service which is built on the REST architecture is called a RESTful service. The underlying protocol for REST is HTTP, which is the basic web protocol. REST stands for REpresentational State Transfer.

Rest and SOAP
1. SOAP is a protocol where REST is an architectural style.
2.SOAP supports ony xml where as REST suppors both xml and Json.
3.SOAP server and client applications are tightly coupled and bind with the WSDL(web service definition lang)  contract. and need to register with UDDI (Universal Description, Discovery, and Integration) where in RSET no contract.
4.Learning curve is easy in REST when compared with SOAP.
5.REST web services request and response can be xml, json and text etc.. where as SOAP works with xml only.
6. JAX-RS is the java API for REST WEB SERVICES
 JAX-WS is the java api FOR SOAP WEBSERVICES or xml based webservices.


REST API Implementations

There are two major implementations of JAX-RS API.
  1. JerseyJersey 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.
  2. RESTEasyRESTEasy is the JBoss project that provides JAX-RS implementation.



  1. POST – This would be used to create a new employee using the RESTful web service
  2. GET - This would be used to get a list of all employee using the RESTful web service
  3. PUT - This would be used to update all employee using the RESTful web service, if not there creates a new one.
  4. DELETE - This would be used to delete all employee using the RESTful web service
PUT actually replace the resource means means full update.

PATCH—do the partially upate the resource.

OPTIONS, -àinformatkon about communication the resoues.

Security:
by using HTTPS: SSL or OAuth.

PUT method is idempotent. So if you send retry a request multiple times, that should be equivalent to single request modification.

POST is NOT idempotent. So if you retry the request N times, you will end up having N resources with N different URIs created on server.

==============
CATEGORY
DESCRIPTION
1xx: Informational
Communicates transfer protocol-level information.
2xx: Success
Indicates that the client’s request was accepted successfully.
3xx: Redirection
Indicates that the client must take some additional action in order to complete their request.
4xx: Client Error
This category of error status codes points the finger at clients.
5xx: Server Error
The server takes responsibility for these error status codes.



200 (OK)




301 (Moved Permanently)


302 (Found)


400 (Bad Request)


401 (Unauthorized)


404 (Not Found)


405 (Method Not Allowed


405 (Method Not Allowed


405 (Method Not Allowed

9.2 OPTIONS

The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.

A request method is considered "idempotent" if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Of the request methods defined by this specification, PUT , DELETE , and safe request methods are idempotent

The HyperText Transfer Protocol (HTTP) 202 Accepted response status code indicates that the request has been received but not yet acted upon. It is non-committal, meaning that there is no way for the HTTP to later send an asynchronous response indicating the outcome of processing the request

The 504 Gateway Timeout error is an HTTP status code that means that one server did not receive a timely response from another server that it was accessing while attempting to load the web page or fill another request by the browser.
=================°


Difference between @RequestParam and @PathVariable


@RequestParam:
It uses query string like below
Http://localhost/getData?name=Prabhu&no=12

and in code

method(@RequestParam(value=name, required=true/false) String name),
@RequestParam(value=no, required=true) String no)

@PathVariable:
It uses query string like below

Http://localhost/getData/Prabhu/12

and in code

@RequestParam("/test/{name,no})

method@PathVariable(value=name)String name),
@RequestParam(value=no) Strino)




No comments:

Post a Comment