RESTful Web Services Introduction

REST Introduction

REST is short form of Representational State Transfer

Rest is architectural style web service which is based on web standards and http protocols(get,post,put,delete).REST was invented by Roy Fielding in 2000.In REST based architecture everything consider as resource, these resources access by common interface based on the HTTP standard methods(get,post,put,delete)

In REST architecture you have server which provide and controls the access to the resources and REST client can access and modify the resources.REST support all the common http operations and resources are accessed by URI

REST allow that resources have different representational styles such as TEXT,HTML,XML,JSON,etc.,Client access the these representation by using URI.

We can create RESTful web service using following methods

  1. Jersey
  2. REST Easy

We will see these in upcoming chapters.

RESTful Web services

RESTful Web services that seamlessly support exposing your data in a variety of representation media types and abstract away the low-level details of the client-server communication is not an easy task without a good toolkit. In order to simplify development of RESTful Web services and their clients in Java, a standard and portable JAX-RS API has been designed.

RESTful webservice are based on REST Architecture and HTTP methods. It is URI bassed service.It support MIME Types(TEXT,XML,HTML,JSON and user defined Objects )

HTTPS Methods

GET -Its defines the reading access of the resource.The resource never get modified by GET request it can only used to access the resources
PUT– It is used to create new resource.
POST– Its is used to update existing resource or create new resource
DELETE – It is used to remove the resources

JAX-RS Using Jersey

Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides it’s own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development. Jersey also exposes numerous extension SPIs so that developers may extend Jersey to best suit their needs.

In server side jersey contains servlet which scans the predefined class to identify the RESTful resouces vai web.xml. Jersey servlet configure in web.xml. The base URL of this servlet name

http://domain-name/your project name/url pattern/ path in your class

The REST servlet receive the incoming then select correct class and methods based on annotations mentioned in the class and produce the result in mentioned type. Rest support Creation of XML and JSON Web service using JAXB(Java Architecture for XML Binding).We will see JAXB in separate chapter

JAX-RX annotations

See below table for few important annotations used in Web Service. JAX-RX contains more annotations

@PATH(path) Set path to your class and methods.This used to call the resource by using base url + path
@POST HTTP Post method.respond with HTTP POST request
@GET HTTP Get method.respond with HTTP GET request
@PUT HTTP Put method.respond with HTTP PUT request
@DELETE HTTP Delete method.respond with HTTP DELETE request
@Produces(any MIME TYPE) @Produces defines which MIME type is returned by a method annotated with @GET.  example “text/plain,”application/xml” or “application/json”,etc.
@Consumes(any MIME TYPE) @Consumes media type consumed by method
@PathParam pass the value in /pathparam
@QueryParam Append the parameters with url query param

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. JAX-RS to Produce JSON using Jackson – Jersey 1.x
  2. JAX-RS get QueryParam using @Context UriInfo
  3. JAX-RS @PathParm Web service Example
  4. Download Text file using JAX-RS RESTful Webservice
  5. Restful Webservice HelloWorld Example Jersey 1.x
  6. JAX-RS Web service to Consume JSON using Jersey 1.x
  7. JAX-RS @GET RESTful webservice
  8. Download image using JAX-RS RESTful Webservice
  9. JAX-RS @POST using RESTful web service – Jersey 1.x
  10. JAX-RS @MatrixParam Restful Webservice
  11. JAX-RS Web Service to produce XML using JAXB
  12. JAX-RS @PATH for URI – Jersey
  13. RESTful Web service to consume JSON and Produce XML – Jersey 1.x
  14. JAX-RS Get HTTP Headers using @HeaderParam
  15. Download PDF file using JAX-RS RESTful Webservice

Be the first to comment

Leave a Reply