RJUG - REST API / JAX-RS Overview
-
Upload
andy-pemberton -
Category
Technology
-
view
341 -
download
1
description
Transcript of RJUG - REST API / JAX-RS Overview
REST APIs
Overview and Jersey / JAX-RS Intro
Andy PembertonRJUG, May 2014
Background
Background
• Front-end guy
• Middleware Java guy
• Agilist, learner, polyglot
• Family guy
REST in a Page
• Architectural Style – a set of constraints
• Nouns and Verbs
• HTTP-Based
• Roy Fielding – U. C. Irvine– “Representational State Transfer”
• Not SOAP
Constraint: Nouns and Verbs
Constraint: Nouns and Verbs
• Nouns– Your business model• Account, Plan, Cat, Dog, Foo, Bar
• Verbs– HTTP-Defined (RFC-2616)• GET, PUT, POST, DELETE• TRACE, OPTIONS, HEAD• PATCH
Examples
BAD
GET /fetch-accountsGET /create-paymentPOST /cancel-payment
GOOD
GET /accountsPOST /paymentDELETE /payments/{id}
Verbs
• GET (idempotent)• PUT (idempotent)• POST• DELETE• PATCH (draft)• TRACE, OPTIONS, HEAD
Specs and Stuff
• JAX-RS – Java API for RESTful Web Services
– JSR-311 – JAX-RS 1.0
– JSR-339 – JAX-RS 2.0• Dependency Injection• Bean Validation• Client API enhancements
Web & Mobile Friendly
Frameworks
• .NET – asp.net web API• Others: Ruby, NodeJS, Scala, Python• Java– Glassfish (Oracle) – Jersey– JBoss – RESTEasy– Restlet– Dropwizard
Jersey
• Oracle Reference Implementation– JSR-311, JSR-339
• Extensions
• Examples Projects
OK - code time, but you got the idea…
Other Constraints
• Client-Server
• Hypermedia contracts (links, hrefs)
• Stateless
API Documentation
• wsdl 2.0, wadl
• apiary.io
• enunciate
• swagger– Mashery I/O Docs
Swagger
• Swagger Core– Annotations– JAX-RS integration– Schema generations
• Swagger UI
Advanced REST
• Partial representationsapi.foobar.com/addresses?select=postalCode
• Resource linking / expansionapi.foobar.com/customers/1234?expand=accounts
• API Versioning
Fin
• References– http://code.google.com/p/implementing-rest/wiki/ByLanguage– https://stormpath.com/blog/linking-and-resource-expansion-res
t-api-tips/
– http://www.mashery.com/product/io-docs