Tải bản đầy đủ - 0trang
Chapter 8. Explore the Power of Restful Web Services
Web service is the way of communication between two or more applications
which have developed for different platforms. These services are independent
of browsers and operating systems which make easy communication and
enhanced performance to target more users. This service can be as easy as a
function, a collection of standards or protocols which has been deployed on
the server. It is a communication between a client and server or
communication between two devices through network. Let's say we
developed a service in Java and published it on internet. Now this service can
be consumed by any Java based applications, but more importantly any .NET
based or Linux based applications can also consume it with the same ease.
This communication is done through set of XML based messages over the
Why we Need of web service?
Interoperatibility is one of the best thing which can be achieved by web
services along with which they provides following
Many applications invest their valuable time in developing complex function
which is already available in other application. Instead of redeveloping it web
services allow developers to explore such services exposed over web. It also
leverages to develop customized client side logic reusing the web services
saving valuable time.
Reusing the developed application
The technologies and market so moving so fast, the developers has to keep on
matching the client requirements. It's very common in development to
redevelop an application using a new platform to support new features with
ease. Instead of developing the complete application from scratch, the
developers can now add enhanced functionalities with whatever the platform
they want, and use the old modules using web services.
Loosely coupled modules
Each service developed as web service is totally independent of any other
services which supports ease of modifying them without any effect on other
part of the application.
Ease in deployment
The web services are deployed over the servers to facilitates the use through
internet. The web service can be deployed over the fire walls to the server
through internet with the same ease as they can be deployed in local servers.
Types of web services
SOAP web service
RESTful web service
RESTful web service is Representational state transfer which is an
architectural style. The RESTfuul resources are revolver around the transfer
of data in some represenatatinal format. The REST resources will be in the
form which needed suits the consumer. It can be in representation forms like
XML, JSON or HTML. In RESTful web services the state of the resource is
more important than the action took against the resource.
Advantages of RESTful web services:
RESTful web services are fast as it consumes less resources and band
It can be written and execute on any platform.
The most important thing is it allows different platforms such as HTML,
XML, Plain text and JSON.
Spring and RESTful web services
Spring supports writing of RestController which can handle requests for
HTTP requests using @RestController annotation. It also provides
@GetMapping, @PostMapping, @DeleteMapping, @PutMapping
annotations to handle HTTP get, post, delete and put methods. The
@PathVariable annotation facilitates access of the values from the URI
template. Current most of the browsers support using GET and POST as
HTTP methods as html actions methods. The HiddenHttpMethodFilter now
enables submission of form for PUT and DEETE methods using