Chapter 4. RESTful Web Services
RESTful Web Services are defined as JSR 339, and the complete specification can be downloaded.
REST is an architectural style of services that utilizes web standards. Web services designed using REST are called RESTful web services, and their main principles are:
Everything can be identified as a resource, and each resource can be uniquely identified by a URI.
A resource can be represented in multiple formats, defined by a media type. The media type will provide enough information on how the requested format needs to be generated. Standard methods are defined for the client and server to negotiate on the content type of the resource.
Use standard HTTP methods to interact with the resource:
GETto retrieve a resource,POSTto create a resource,PUTto update a resource, andDELETEto remove a resource.Communication between the client and the endpoint is stateless. All the associated state required by the server is passed by the client in each invocation.
Java API for RESTful web services (JAX-RS) defines a standard annotation-driven API that helps developers build a RESTful web service in Java and invoke it. The standard principles of REST, such as identifying a resource as a URI, a well-defined set of methods to access the resource, and multiple representation formats of a resource, can be easily marked in a POJO via annotations.
Resources
A simple RESTful web service can be defined as a resource
using @Path:
@Path("orders")publicclassOrderResource{
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access