RESTful Web Services Introduction

REST Introduction

REST is short form of Representational State Transfer

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

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

To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

Posts You may Like

  1. Sending HTML Email using Java Mail API
  2. How to create XML file using DOM Parser
  3. How to find min and max value from Collection
  4. Java 7 new features
  5. Java 8 Overview and New Features
  6. Java 7 Switch statement on String
  7. How to validate password using Java Regular Expression
  8. Java 8 New Features Overview
  9. How to Convert JSON String to Object using GSON
  10. Java 8 Stream Filter with findAny orElse Example
  11. Java 7 Binary Literals
  12. Log4j Basic Configurator Example
  13. Log4j Architecture
  14. How to Create Folder using Java File.mkdirs()
  15. JAX-RS QueryParam – Jersey

Be the first to comment

Leave a Reply

Your email address will not be published.