Notes about RESTful Service
We already discussed about the RESTful service compare with SOAP Service and etc. Here will point out the important notes about the RESTful Services . Hope it will useful while preparing the interview
When we exposing any Service /API followings are mandatory
1) Accessibility ie How to access the Service
2) Request and Response
3) How to handle the exception
4) Versioning
5) Security
6) Performance
REST is nothing but Representation State Transfer and its architecture style and RESTful is a mainly for exposing the Webservices access through HTTP.
RESTful does not maintains any state between the Server and Client ,
Its stateless service .
Stateless service always create the new request whenever client communicate with Server.
Always independent Request between Client and Server
RESTful service transports through HTTP Protocol ofcourse its supports HTTPS also.
RESTful service transfer the different data format ie its supports XML/JSON and etc. In Enterprise level JSON is very familiar in RESTful service world since its easily readable and does not need a parser to compile and etc.
Another Advantages of RESTful with JSON , We can persists the JSON object directly in the DB . Recent days DB supports JSON Data Type .
Ex: Postgresql and Oracle Latest version
It will reduced the development and Processing time between JSON and Primitive Data Types while its persists in DB
RESTful can be access through URI , Resource should be unique .
RESTful will supports following verbs from Http
GET
POST
PUT
Options
DElete
HEADER
Above methods are working based on Idempotent , means it will always gives the same result regardless how many operations and how many times invoked
PUT and Delete based on the Idempotent , GET maintains the read state and post does not Idempotent
Ex: When we invoke the Put operation , it always returns the same result mainly used for Update if its exists otherwise it will create the new
However the Post operation always returns new since does not supports idempotent
Verbs are used for following Usecases
GET -- READ
PUT -UPDATE
DELETE-DELETE
OPTIONS- Check the options
POST -- CREATE/UPDATE
HEADER- Store the HEADER Inform
In WebService world Request and Response are mandatory ie when we invoke the service we need to pass the request and we will get the response from Service
Parts of Request
URI
VERB
REQUEST HEADER
REQUEST BODY
HTTP VERSION
Similarly Response also have the followings
URI
VERB
STATUS CODE
RESPONSE HEADER
RESPONSE BODY
HTTP VERSION
above attributes are populates based on the VERB/Operations
RESTful services based on JAX-RS specification , Initial version only synchronous But JAX-RS 2.0 supports ASync also
RESTful Service supports Cache in built capability which used to store the infor in the Client instead of accessing the same data from Server with specific window.
Cache Attributes define in the HTTP Response Header like Cache /no -cache/MAx Time/etc
Recommendation for Cache, We can cache the static data/images and etc with specific window
RESTful service always returns the status code in the response . Its starts from 200/300/400/500 series
Its normal controller class we can expose as RESTful service in the following ways
@Controller
@RESTController
What are the difference between the above approach
Controller have method/operation always rendering in server side and return as view
RESTController , its returns the Response
Controller does not support the RESPONSE Body , REST controller does supports
Again one more doubt in my mind always what is the difference between RESTful and Servlet since both are Servlet and access through HTTP protocol ?
As per my understanding is
RESTful service access the operation through Resources But servlet does not .
RESTful transport the different data format But Servlet does not
In General , RESTful is vanilla flavour of Servlet API , above are not exactly the difference its an additional Features in RESTful
Versioning in RESTful , In the enterprise world Versioning is mandatory for all the API Regardless its Service or Plain Java and etc.
Whenever there is a change with out backward compatibility ie break the existing consumer then Versioning in the place , We can implement the versioning in RESTful following ways
1) Version number in the URI
2) Passing the Version number in the query parameters
3) Pass the version number in Header
Still we can maintains the version with out breaking Consumer using API Gateway , We will talk about API Gateway very soon.
Security
We can implement the Security in RESTful service in the following
1) HttpBasic Authentication - Check/Validate the User Credential
2) Token Based Authentication
3) OAuth2.0 - Authorization
RAML
Hope you are more familiar in SOAP Service , In the SOAP Service's world we can define our contract ie WSDL /XSD which used to define the operation/Request /Response/Exception and etc
In the RESTful service world . we can define our schema ie define the Version/URI/Operation and Query Parameters using RAML .
RAML is REST API Modelling language which is used to manage the API Life cycle .
Its mainly used to describe your REST API .
Lastly discussed about the Exception Handling in RESTful service either we can implement the Exception Handler/Exception Filter/CustomAdvise for Exception .
will put sample code for above in GITHub soon
When we exposing any Service /API followings are mandatory
1) Accessibility ie How to access the Service
2) Request and Response
3) How to handle the exception
4) Versioning
5) Security
6) Performance
REST is nothing but Representation State Transfer and its architecture style and RESTful is a mainly for exposing the Webservices access through HTTP.
RESTful does not maintains any state between the Server and Client ,
Its stateless service .
Stateless service always create the new request whenever client communicate with Server.
Always independent Request between Client and Server
RESTful service transports through HTTP Protocol ofcourse its supports HTTPS also.
RESTful service transfer the different data format ie its supports XML/JSON and etc. In Enterprise level JSON is very familiar in RESTful service world since its easily readable and does not need a parser to compile and etc.
Another Advantages of RESTful with JSON , We can persists the JSON object directly in the DB . Recent days DB supports JSON Data Type .
Ex: Postgresql and Oracle Latest version
It will reduced the development and Processing time between JSON and Primitive Data Types while its persists in DB
RESTful can be access through URI , Resource should be unique .
RESTful will supports following verbs from Http
GET
POST
PUT
Options
DElete
HEADER
Above methods are working based on Idempotent , means it will always gives the same result regardless how many operations and how many times invoked
PUT and Delete based on the Idempotent , GET maintains the read state and post does not Idempotent
Ex: When we invoke the Put operation , it always returns the same result mainly used for Update if its exists otherwise it will create the new
However the Post operation always returns new since does not supports idempotent
Verbs are used for following Usecases
GET -- READ
PUT -UPDATE
DELETE-DELETE
OPTIONS- Check the options
POST -- CREATE/UPDATE
HEADER- Store the HEADER Inform
In WebService world Request and Response are mandatory ie when we invoke the service we need to pass the request and we will get the response from Service
Parts of Request
URI
VERB
REQUEST HEADER
REQUEST BODY
HTTP VERSION
Similarly Response also have the followings
URI
VERB
STATUS CODE
RESPONSE HEADER
RESPONSE BODY
HTTP VERSION
above attributes are populates based on the VERB/Operations
RESTful services based on JAX-RS specification , Initial version only synchronous But JAX-RS 2.0 supports ASync also
RESTful Service supports Cache in built capability which used to store the infor in the Client instead of accessing the same data from Server with specific window.
Cache Attributes define in the HTTP Response Header like Cache /no -cache/MAx Time/etc
Recommendation for Cache, We can cache the static data/images and etc with specific window
RESTful service always returns the status code in the response . Its starts from 200/300/400/500 series
Its normal controller class we can expose as RESTful service in the following ways
@Controller
@RESTController
What are the difference between the above approach
Controller have method/operation always rendering in server side and return as view
RESTController , its returns the Response
Controller does not support the RESPONSE Body , REST controller does supports
Again one more doubt in my mind always what is the difference between RESTful and Servlet since both are Servlet and access through HTTP protocol ?
As per my understanding is
RESTful service access the operation through Resources But servlet does not .
RESTful transport the different data format But Servlet does not
In General , RESTful is vanilla flavour of Servlet API , above are not exactly the difference its an additional Features in RESTful
Versioning in RESTful , In the enterprise world Versioning is mandatory for all the API Regardless its Service or Plain Java and etc.
Whenever there is a change with out backward compatibility ie break the existing consumer then Versioning in the place , We can implement the versioning in RESTful following ways
1) Version number in the URI
2) Passing the Version number in the query parameters
3) Pass the version number in Header
Still we can maintains the version with out breaking Consumer using API Gateway , We will talk about API Gateway very soon.
Security
We can implement the Security in RESTful service in the following
1) HttpBasic Authentication - Check/Validate the User Credential
2) Token Based Authentication
3) OAuth2.0 - Authorization
RAML
Hope you are more familiar in SOAP Service , In the SOAP Service's world we can define our contract ie WSDL /XSD which used to define the operation/Request /Response/Exception and etc
In the RESTful service world . we can define our schema ie define the Version/URI/Operation and Query Parameters using RAML .
RAML is REST API Modelling language which is used to manage the API Life cycle .
Its mainly used to describe your REST API .
Lastly discussed about the Exception Handling in RESTful service either we can implement the Exception Handler/Exception Filter/CustomAdvise for Exception .
will put sample code for above in GITHub soon
Comments
Post a Comment