SlideShare a Scribd company logo
By NeeravArora (Cerner Healthcare Solutions Pvt Ltd.)
&
Kumaraswamy M (IBM)
REST with Java (JAX-RS) and Jersey
Agenda
 Rest API concepts .
 Foundation .
 JAX-RS and Jersey .
 Setting up Jersey project in eclipse.
 JAX-RS annotations .
 CRUD app.
 Restful API’s with Swagger.
Rest API Concepts
 Services exposed to internet for programmatic access
 Users can be either producers or consumers or both
 Eg : api.twitter.com
 Data can be returned in the form of XML /JSON / etc
 Helps developers to parse data.
 Messages can be exchanged in any kind of HTTP method
Foundation
Nouns (Resources)
unconstrained
i.e., http://example.com/employees/12345
Representations
constrained
i.e., XML
Verbs
constrained
i.e., GET
Resources
 REST uses URI to identify resources .
 http://localhost/books/
 http://localhost/books/ISBN-0011
 http://localhost/books/ISBN-0011/authors
 http://localhost/classes
 http://localhost/classes/cs2650
 http://localhost/classes/cs2650/students
 As you traverse the path from more generic to more
specific, you are navigating the data .
Action/Verb
 /orders
 GET - list all orders
 POST - submit a new order
 /orders/{order-id}
 GET - get an order representation
 PUT - update an order
 DELETE - cancel an order
 /orders/average-sale
 GET - calculate average sale
 /customers
 GET - list all customers
 POST - create a new customer
 /customers/{cust-id}
 GET - get a customer representation
 DELETE- remove a customer
 /customers/{cust-id}/orders
 GET - get the orders of a customer
Representations (MediaType)
 XML
<COURSE>
<ID>CS2650</ID>
<NAME>Distributed Multimedia Software</NAME>
</COURSE>
 JSON
{“course”: {
“id”: “CS2650”
“name”: “Distributed Multimedia Software”
}
}
Why it is called “REST” ?
JAX-RS
 Java API for RESTfulWeb Services .
 Provides support in creating web services according to the
Representational StateTransfer (REST) architectural pattern .
 Uses annotations .
Jersey
 One of the libraries that implements JAX-RS , from Oracle.
 Other libraries in the market -
* Apache CXF , an open sourceWeb service framework .
* RESTeasy, JBoss 's implementation .
* Restlet .
* ApacheWink ,Apache Software Foundation Incubator .
*WebSphereApplication Server from IBM.
 Choice of library doesn’t matter .
Big Picture
Big Picture (contd…)
Your first Jersey project
Your first Jersey project (contd…)
http://repo1.maven.org/maven2/archetype-catalog.xml
Your first Jersey project (contd…)
Your first Jersey project (contd…)
Your first Jersey project (contd…)
Your first Jersey project (contd…)
Root resource class
@Path
Sets the path to base URL + /your_path.The base URL is based on your application name,
the servlet and the URL pattern from the web.xml configuration file.
@GET, @PUT, @POST, @DELETE, ...
@Produces
@Produces defines which MIME type is delivered by a method annotated with @GET. In
the example text ("text/plain") is produced. Other examples would be "application/xml"
or "application/json"
@PathParam
Used to inject values from the URL into a method parameter.This way you inject,
for example, the ID of a resource into the method to get the correct object.
@Consumes
@Consumes defines which MIME type is consumed by this method.
CRUD App example (Model)
CRUD App example (Model)
CRUD App example (Database)
CRUD App example (Service)
Crud App (Resource)
RESTFul APIs with Swagger
What is Swagger and Why Swagger?
• Simple representation of your RESTFul API
• Declarative resource specification
• JSON specification
• Swagger UI to interact with the API in a sandbox UI
• Why Jersey Client / JUNIT for your client or boss?
• Developers and documentation… hahaha
• Support your existing RESTFul API without change
Swagger Specification
• Resource Listing
• API Description
Create Swagger Specification
• Codgen - converts annotations in your code into swagger
specification
• Manually - writing the JSON by hand
Swagger Specification
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
References
• http://www.vogella.com/tutorials/REST/article.html
• https://jersey.java.net/documentation/latest/jaxrs-
resources.html
• https://github.com/koushikkothagal/messenger
• http://swagger.io/specification/
• https://github.com/swagger-api/swagger-spec
• https://github.com/swagger-api/swagger-core
• http://petstore.swagger.io/
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey

More Related Content

PDF
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
PPT
Developing RESTful WebServices using Jersey
PPTX
RESTEasy
PPTX
Introduction to RESTful Webservices in JAVA
PPTX
RESTful Web Services
PPTX
Rest presentation
PPTX
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
PDF
Making Java REST with JAX-RS 2.0
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Developing RESTful WebServices using Jersey
RESTEasy
Introduction to RESTful Webservices in JAVA
RESTful Web Services
Rest presentation
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
Making Java REST with JAX-RS 2.0

What's hot (20)

PPTX
Design Beautiful REST + JSON APIs
PPTX
Rest and Rails
PPTX
REST & RESTful Web Services
PPT
Using Java to implement RESTful Web Services: JAX-RS
PPTX
Rest and Sling Resolution
PPTX
REST presentation
PDF
Rest web services
PPT
Rest in Rails
PDF
Creating Restful Web Services with restish
PPTX
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
PDF
REST - Representational state transfer
PDF
HATEOAS: The Confusing Bit from REST
PDF
Building RESTful applications using Spring MVC
PDF
Spring Web Services: SOAP vs. REST
PDF
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
ODP
REST API Laravel
PPT
The RESTful Soa Datagrid with Oracle
PPTX
WebLogic Developer Webcast 1: JPA 2.0
PDF
PPTX
Restful web services with java
Design Beautiful REST + JSON APIs
Rest and Rails
REST & RESTful Web Services
Using Java to implement RESTful Web Services: JAX-RS
Rest and Sling Resolution
REST presentation
Rest web services
Rest in Rails
Creating Restful Web Services with restish
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
REST - Representational state transfer
HATEOAS: The Confusing Bit from REST
Building RESTful applications using Spring MVC
Spring Web Services: SOAP vs. REST
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
REST API Laravel
The RESTful Soa Datagrid with Oracle
WebLogic Developer Webcast 1: JPA 2.0
Restful web services with java
Ad

Similar to Eclipse Day India 2015 - Rest with Java (jax rs) and jersey (20)

PPTX
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
PPTX
Building Restful Web Services with Java
PPTX
Rest overview briefing
PDF
PPTX
RESTful Web Service using Swagger
PPTX
Introducing swagger
PPTX
JAX-RS. Developing RESTful APIs with Java
PPTX
Ppt on web development and this has all details
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PPTX
RJUG - REST API / JAX-RS Overview
PDF
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
PPTX
RESTful application with JAX-RS and how to expose and test them
PDF
Hia 1691-using iib-to_support_api_economy
PPTX
Restful webservice
PPTX
Overview of RESTful web services
PDF
RESTful Web Services with Jersey
PDF
JAX-RS Creating RESTFul services
PPTX
Super simple introduction to REST-APIs (2nd version)
PDF
From Open Source to Open API with Restlet
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
Building Restful Web Services with Java
Rest overview briefing
RESTful Web Service using Swagger
Introducing swagger
JAX-RS. Developing RESTful APIs with Java
Ppt on web development and this has all details
RESTful Java With JAX RS 1st Edition Bill Burke
RESTful Java With JAX RS 1st Edition Bill Burke
RJUG - REST API / JAX-RS Overview
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
RESTful application with JAX-RS and how to expose and test them
Hia 1691-using iib-to_support_api_economy
Restful webservice
Overview of RESTful web services
RESTful Web Services with Jersey
JAX-RS Creating RESTFul services
Super simple introduction to REST-APIs (2nd version)
From Open Source to Open API with Restlet
Ad

More from Eclipse Day India (20)

PPTX
Java Performance Testing for Everyone - Shelley Lambert
PDF
Eclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
PDF
Pattern Matching in Java - Srikanth Sankaran
PDF
Machine Learning for Java Developers - Nasser Ebrahim
PPTX
Scaling Eclipse on HiDPI Monitors - Niraj Modi
PPTX
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
PDF
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
PDF
Eclipse Day India 2015 - Java bytecode analysis and JIT
PPTX
Eclipse Day India 2015 - Java 8 Overview
ODP
Eclipse Day India 2015 - Java 9
PDF
Eclipse Day India 2015 - Keynote - Stephan Herrmann
PDF
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
PDF
Eclipse Day India 2015 - Oomph
PDF
Eclipse Day India 2015 - Keynote (Mike Milinkovich)
PDF
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
PDF
IDS and Bluemix
PPT
SWT - Technical Deep Dive
PPTX
PDE builds or Maven
PPT
Orion - IDE on the cloud
Java Performance Testing for Everyone - Shelley Lambert
Eclipse IDE Tips and Tricks - Lakshmi Priya Shanmugam
Pattern Matching in Java - Srikanth Sankaran
Machine Learning for Java Developers - Nasser Ebrahim
Scaling Eclipse on HiDPI Monitors - Niraj Modi
Please Behave Yourself: BDD and automating Eclipse RCP applications using JBe...
Supporting Java™ 9 in Eclipse - A critical perspective - Stephan Herrmann
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 9
Eclipse Day India 2015 - Keynote - Stephan Herrmann
Eclipse Day India 2015 - Eclipse RCP testing using Jubula based automation
Eclipse Day India 2015 - Oomph
Eclipse Day India 2015 - Keynote (Mike Milinkovich)
Eclipse Day India 2015 - Unleashing the Java 8 Tooling in Eclipse
IDS and Bluemix
SWT - Technical Deep Dive
PDE builds or Maven
Orion - IDE on the cloud

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Cloud computing and distributed systems.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Cloud computing and distributed systems.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Eclipse Day India 2015 - Rest with Java (jax rs) and jersey