Professional Documents
Culture Documents
C3: Protected
About the Author
Hands on
Questions Tools Exercise
A Welcome
Demonstration Contacts
Break
Objective:
After completing this chapter you will be able to:
Create a RESTful web service
Consume a RESTful web service
Addressability
Addressability is the idea that every object and resource in
your system is reachable through a unique identifier.
In the REST world, addressability is managed through the use
of URIs.
The format of a URI is standardized as follows:
scheme://host:port/path?queryString#fragment
The Uniform, Constrained Interface
The idea behind it is that you stick to the finite set of
operations of the application protocol you’re distributing your
services upon.
Representation-Oriented
In a RESTful system, the complexity of the client-server
interaction is within the representations being passed back
and forth. These representations could be XML, JSON etc
Communicate Statelessly
Stateless means that there is no client session data stored on
the server. The server only records and manages the state of
the resources it exposes.
HATEOAS
The final principle of REST is the idea of using Hypermedia As
The Engine Of Application State (HATEOAS).
Representatio
Resources URI
ns
• Anything the • A unique • Any useful
client might identifier for information
want to a resource, about the
reference or made of a state of a
interact with, name and a resource
any piece of structured
information address
that might be indicating
worthwhile where to find
referencing this resource.
in a
hyperlink
The BookResource is a Java class annotated with @Path, indicating that the resource
will be hosted at the URI path /book.
The getBookTitle() method is marked to process HTTP GET requests (using @GET
annotation) and produces text (the content is identified by the MIME Media
text/plain).
To access this resource, you need an HTTP client such as a browser and an HTTP
GET method to point to the URL http://localhost:8080/bookweb/book.
The @Path annotation's value is a relative URI path. When used on classes,
these are referred to as root resources, providing the roots of the resource
tree and access to subresources.
URI path templates are also used with variables embedded within the URI
syntax. Those variables are evaluated at runtime.
@Path("/customers/{customername}")
@Path may also be used on methods of root resources, which can be useful
to group together common functionalities for several resources
If @Path exists on both the class and method, the relative path to the
resource method is a concatenation of the class and method. For example,
to get a book by its ID, the path will be /items/books/1234
@PathParam
@Path("/books/{bookid}")
public Book getBook(@PathParam("bookid") String bookId)
Uri: http://url/customers/98342
@QueryParam
public Customer getCustomerByZipCode(@QueryParam("zip") Long zip) {
Uri: http://url/customers?zip=19870
Thank You !
http://www.eclipse.org/webtools
http://www.w3.org/TR/wsdl
http://ws.apache.org/axis2/
Disclaimer: Parts of the content of this course is based on the materials available from the Web sites and books
listed above. The materials that can be accessed from linked sites are not maintained by Cognizant Academy and
we are not responsible for the contents thereof. All trademarks, service marks, and trade names in this course are
the marks of the respective owner(s).