SlideShare a Scribd company logo
SDC  2008 REST  made simple with Java
Niklas Gustavsson [email_address] http://protocol7.com http://twitter.com/protocol7
REST made simple with Java
REST?
HTTP 1.1
Some HTTP history
Some HTTP history
HTTP done right
 
Principles
Principles Everything is a resource
Principles A resource has an identifier http://example.com/customers/1453
Principles We transfer representations
Principles All resources expose a uniform interface  GET, POST, PUT, DELETE
Principles Hypermedia as the engine of application state
Principles Client-server, Stateless, Cacheable, Layered
Why?
Why? It's easy! Well, it's not
Why? It's what the cool kids use
Why? Web has been successful, copy!
Why? It's what others use
Why? Interoperability on the right level
Frameworks, yeay!
JAX-RS (aka JSR-311)
Jersey  http://jersey.dev.java.net Restlets  http://www.restlet.org RESTeasy  http://www.jboss.org/resteasy CXF  http://cxf.apache.org
POJO based Annotation heavy
Resources
Code! Show me the code!
public class TimeReportService { private TimeReportDao reportDao; public TimeReport getReport(String username) { return reportDao.forUser(username); } public void saveReport(TimeReport report) { reportDao.update(report); }   ... }
Request mapping
@Path("report") public class TimeReportService { private TimeReportDao reportDao; @GET public TimeReport getReport(String username) { return reportDao.forUser(username); } @PUT public void saveReport(TimeReport report) { reportDao.update(report); }   ... }
 
public class TimeReportApplication extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> resources = new HashSet<Class<?>>(); resources.add(TimeReportService.class); return resources; } }
Path parameters and contexts
@Path(&quot;{username}/report&quot;) public class TimeReportService { @GET public TimeReport getReport(@PathParam(&quot;username&quot;)  String username) { return reportDao.forUser(username); } ... } http://example.com/niklas/report
@GET public TimeReport getReport(@Context SecurityContext sc) { if(sc.isSecure()) { Principal user = sc.getUserPrincipal(); return reportDao.forUser(user.getName()); } else { ... throw error, redirect to login  }  }
@GET public TimeReport getReport(@CookieParam(&quot;username&quot;)  String username) { return reportDao.forUser(username); }
 
Any media type is allowed XML, JSON, text/plain, Binary files, ...
Entity providers MessageBodyReader, MessageBodyWriter
Standard Entity providers
 
Writing your own Entity provider
BEGIN:VFREEBUSY DTSTART:20090324T080000Z DTEND:20090324T170000Z DTSTAMP:20090316T123136Z UID:ca668b14ddf589ea8650b0b992eb64a656cdbc7e@google.com SUMMARY:SDC2009 END:VFREEBUSY
@Provider @Produces(&quot;text/calendar&quot;) public class TimeReportICalWriter implements  MessageBodyWriter<TimeReport> { public void writeTo(TimeReport t, Class<?> type, Type  genericType,Annotation[] annotations,MediaType  mediaType,MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) { PrintWriter wr = new PrintWriter(entityStream); ... for(TimeRange range : t.getRanges())  { wr.println(&quot;BEGIN:VFREEBUSY&quot;); wr.println(&quot;DTSTART:&quot; + DF.format(range.getStartTime())); wr.println(&quot;DTEND:&quot; + DF.format(range.getEndTime())); wr.println(&quot;SUMMARY:&quot; + range.getDescription()); wr.println(&quot;END:VFREEBUSY&quot;); } ... }
Response, ResponseBuilder
Exception  Mapping
Deployment
JAX-RS limitations
JAX-RS limitations Lifecycle support
JAX-RS limitations Weak support for links, caching, method tunneling
JAX-RS limitations Accept based content  negotiation  only http://example.com/report http://example.com/report.xml http://example.com/report.cal http://example.com/report.json
JAX-RS limitations Limited security support
JAX-RS limitations Leaky abstraction
Try it out! And have a look at the alternatives
Want more?
Questions?
[email_address]
Attributions http://www.flickr.com/photos/psd/421186578/ http://www.flickr.com/photos/sineout/2491569707/ http://www.flickr.com/photos/apelad/sets/72157594388426362/ http://www.flickr.com/photos/goopymart/289959670

More Related Content

ODP
Oredev 2009 JAX-RS
PPT
Introduction to JAX-RS
PDF
Brief Intro To Jax Rs
PDF
Whats New in the Http Service Specification - Felix Meschberger
PPT
Developing RESTful WebServices using Jersey
ODP
RestFull Webservices with JAX-RS
PDF
RESTful Web Services in Drupal7
PDF
RESTful Web Services with Jersey
Oredev 2009 JAX-RS
Introduction to JAX-RS
Brief Intro To Jax Rs
Whats New in the Http Service Specification - Felix Meschberger
Developing RESTful WebServices using Jersey
RestFull Webservices with JAX-RS
RESTful Web Services in Drupal7
RESTful Web Services with Jersey

What's hot (15)

PDF
So various polymorphism in Scala
PPT
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
PDF
Jersey and JAX-RS
PDF
PDF
Dropwizard
PDF
Services in Drupal 8
PPTX
Percona Live London 2014 - MySQL Backup Strategy @ IEDR
PDF
JavaEE and RESTful development - WSO2 Colombo Meetup
PDF
Java colombo-deep-dive-into-jax-rs
PDF
Apache Beam de A à Z
PDF
the Spring 4 update
PDF
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
PDF
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
PPTX
Database Connection Pooling With c3p0
PDF
So various polymorphism in Scala
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Jersey and JAX-RS
Dropwizard
Services in Drupal 8
Percona Live London 2014 - MySQL Backup Strategy @ IEDR
JavaEE and RESTful development - WSO2 Colombo Meetup
Java colombo-deep-dive-into-jax-rs
Apache Beam de A à Z
the Spring 4 update
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Database Connection Pooling With c3p0
Ad

Viewers also liked (15)

PDF
Spotify services (SDC 2013)
PDF
Spotify services - Leetspeak 2014
PPTX
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
PDF
Modern Software Architecture Styles and Patterns
PDF
The Modern Software Architect
PDF
Spotify architecture - Pressing play
PDF
Spotify: Data center & Backend buildout
PPTX
Software Architecture Patterns
PDF
Big Data At Spotify
PDF
A Spotify Presentation - Case studies
PDF
Algorithmic Music Recommendations at Spotify
PDF
Music Recommendations at Scale with Spark
PDF
Scala Data Pipelines for Music Recommendations
PDF
Interactive Recommender Systems with Netflix and Spotify
PDF
From Idea to Execution: Spotify's Discover Weekly
Spotify services (SDC 2013)
Spotify services - Leetspeak 2014
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architecture Styles and Patterns
The Modern Software Architect
Spotify architecture - Pressing play
Spotify: Data center & Backend buildout
Software Architecture Patterns
Big Data At Spotify
A Spotify Presentation - Case studies
Algorithmic Music Recommendations at Spotify
Music Recommendations at Scale with Spark
Scala Data Pipelines for Music Recommendations
Interactive Recommender Systems with Netflix and Spotify
From Idea to Execution: Spotify's Discover Weekly
Ad

Similar to REST made simple with Java (20)

PDF
REST made simple with Java
PDF
CDI, Seam & RESTEasy: You haven't seen REST yet!
ODP
Codemotion appengine
PPTX
RESTful Web Services
PDF
Creating a Web of Data with Restlet
PDF
Secc tutorials development and deployment of rest web services in java_v2.0
PDF
Rest with Spring
PDF
ERRest - The Next Steps
PPTX
Mendix rest services
PDF
ERRest and Dojo
PPTX
PDF
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
PPTX
Web Basics
PPT
Tu1 1 5l
PDF
JAX-RS JavaOne Hyderabad, India 2011
PPTX
JAX-RS 2.0 and OData
PDF
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
PPT
Using Java to implement RESTful Web Services: JAX-RS
PPTX
Overview of RESTful web services
REST made simple with Java
CDI, Seam & RESTEasy: You haven't seen REST yet!
Codemotion appengine
RESTful Web Services
Creating a Web of Data with Restlet
Secc tutorials development and deployment of rest web services in java_v2.0
Rest with Spring
ERRest - The Next Steps
Mendix rest services
ERRest and Dojo
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
Web Basics
Tu1 1 5l
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS 2.0 and OData
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Using Java to implement RESTful Web Services: JAX-RS
Overview of RESTful web services

More from Niklas Gustavsson (7)

KEY
Real-time web
PPT
RESTful web services
PPT
Not only SQL
KEY
The future is bright
PPT
ODP
Apachecon Eu 2008 Mina
Real-time web
RESTful web services
Not only SQL
The future is bright
Apachecon Eu 2008 Mina

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
1. Introduction to Computer Programming.pptx
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25-Week II
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
SOPHOS-XG Firewall Administrator PPT.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
1. Introduction to Computer Programming.pptx

REST made simple with Java