SlideShare ist ein Scribd-Unternehmen logo
1 von 59
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

Weitere ähnliche Inhalte

Was ist angesagt?

Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Marco Gralike
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
Andrei Jechiu
 

Was ist angesagt? (15)

So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
 
Jersey and JAX-RS
Jersey and JAX-RSJersey and JAX-RS
Jersey and JAX-RS
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
Percona Live London 2014 - MySQL Backup Strategy @ IEDR
Percona Live London 2014 - MySQL Backup Strategy @ IEDRPercona Live London 2014 - MySQL Backup Strategy @ IEDR
Percona Live London 2014 - MySQL Backup Strategy @ IEDR
 
JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
Apache Beam de A à Z
 Apache Beam de A à Z Apache Beam de A à Z
Apache Beam de A à Z
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
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 - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
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
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
 
Database Connection Pooling With c3p0
Database Connection Pooling With c3p0Database Connection Pooling With c3p0
Database Connection Pooling With c3p0
 
Kommons
KommonsKommons
Kommons
 

Andere mochten auch

Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and MobileModern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Dan Mohl
 
Big Data At Spotify
Big Data At SpotifyBig Data At Spotify
Big Data At Spotify
Adam Kawa
 
Interactive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and SpotifyInteractive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and Spotify
Chris Johnson
 

Andere mochten auch (15)

Spotify services (SDC 2013)
Spotify services (SDC 2013)Spotify services (SDC 2013)
Spotify services (SDC 2013)
 
Spotify services - Leetspeak 2014
Spotify services - Leetspeak 2014Spotify services - Leetspeak 2014
Spotify services - Leetspeak 2014
 
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and MobileModern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
 
Modern Software Architecture Styles and Patterns
Modern Software Architecture Styles and PatternsModern Software Architecture Styles and Patterns
Modern Software Architecture Styles and Patterns
 
The Modern Software Architect
The Modern Software ArchitectThe Modern Software Architect
The Modern Software Architect
 
Spotify architecture - Pressing play
Spotify architecture - Pressing playSpotify architecture - Pressing play
Spotify architecture - Pressing play
 
Spotify: Data center & Backend buildout
Spotify: Data center & Backend buildoutSpotify: Data center & Backend buildout
Spotify: Data center & Backend buildout
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
Big Data At Spotify
Big Data At SpotifyBig Data At Spotify
Big Data At Spotify
 
A Spotify Presentation - Case studies
A Spotify Presentation - Case studiesA Spotify Presentation - Case studies
A Spotify Presentation - Case studies
 
Algorithmic Music Recommendations at Spotify
Algorithmic Music Recommendations at SpotifyAlgorithmic Music Recommendations at Spotify
Algorithmic Music Recommendations at Spotify
 
Music Recommendations at Scale with Spark
Music Recommendations at Scale with SparkMusic Recommendations at Scale with Spark
Music Recommendations at Scale with Spark
 
Scala Data Pipelines for Music Recommendations
Scala Data Pipelines for Music RecommendationsScala Data Pipelines for Music Recommendations
Scala Data Pipelines for Music Recommendations
 
Interactive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and SpotifyInteractive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and Spotify
 
From Idea to Execution: Spotify's Discover Weekly
From Idea to Execution: Spotify's Discover WeeklyFrom Idea to Execution: Spotify's Discover Weekly
From Idea to Execution: Spotify's Discover Weekly
 

Ähnlich wie REST made simple with Java

REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
elliando dias
 
03 form-data
03 form-data03 form-data
03 form-data
snopteck
 
Java Technology
Java TechnologyJava Technology
Java Technology
ifnu bima
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 

Ähnlich wie REST made simple with Java (20)

REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
REST
RESTREST
REST
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
JAX-RS.next
JAX-RS.nextJAX-RS.next
JAX-RS.next
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
 
Internet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian ThilmanyInternet Explorer 8 for Developers by Christian Thilmany
Internet Explorer 8 for Developers by Christian Thilmany
 
03 form-data
03 form-data03 form-data
03 form-data
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
soft-shake.ch - JAX-RS and Java EE 6
soft-shake.ch - JAX-RS and Java EE 6soft-shake.ch - JAX-RS and Java EE 6
soft-shake.ch - JAX-RS and Java EE 6
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache Tuscany
 
Hammock, a Good Place to Rest
Hammock, a Good Place to RestHammock, a Good Place to Rest
Hammock, a Good Place to Rest
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 

Mehr von Niklas Gustavsson (7)

Real-time web
Real-time webReal-time web
Real-time web
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Not only SQL
Not only SQL Not only SQL
Not only SQL
 
HTML5
HTML5HTML5
HTML5
 
The future is bright
The future is brightThe future is bright
The future is bright
 
CouchDB
CouchDBCouchDB
CouchDB
 
Apachecon Eu 2008 Mina
Apachecon Eu 2008 MinaApachecon Eu 2008 Mina
Apachecon Eu 2008 Mina
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

REST made simple with Java