SlideShare une entreprise Scribd logo
1  sur  62
Télécharger pour lire hors ligne
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Building Smart Clients with Spring
by Josh Long and Roy Clarkson
WHAT IS REST?
REST is an architectural constraint based on HTTP 1.1,
and created as part of Roy Fielding’s doctoral
dissertation in 2000.
It embraces HTTP.
It’s a style, not a standard
http://en.wikipedia.org/wiki/Representational_state_transfer
WHAT IS REST?
REST has no hard and fast rules.
REST is an architectural style, not a standard.
REST uses Headers to describe requests & responses
REST embraces HTTP verbs
HTTP VERBS
GET /users/21
GET requests retrieve information.
GET can have side-effects (but it’s unexpected)
GET can be conditional, or partial:
If-Modified-Since, Range
HTTP VERBS
DELETE requests that a resource be removed, though
the deletion doesn’t have to be immediate.
DELETE /users/21
HTTP VERBS
POST requests that the resource do something with the
enclosed entity
POST can be used to create or update.
POST /users
{ “firstName”: “Juergen” }
HTTP VERBS
PUT requests that the entity be stored at a URI
PUT can be used to create or update.
PUT /users/21
{ “firstName”: “Juergen” }
THE MATURITY MODEL
The Richardson Maturity Model is a way to grade your
API according to the REST constraints with 4 levels of
increasing compliance
http://martinfowler.com/articles/richardsonMaturityModel.html
THE MATURITY MODEL
The Richardson Maturity Model
Level 0: swamp of POX
http://martinfowler.com/articles/richardsonMaturityModel.html
Uses HTTP mainly as a tunnel through one URI
e.g., SOAP, XML-RPC
Usually features on HTTP verb (POST)
THE MATURITY MODEL
The Richardson Maturity Model
Level 1: resources
http://martinfowler.com/articles/richardsonMaturityModel.html
Multiple URIs to distinguish related nouns
e.g., /articles/1, /articles/2, vs. just /articles
THE MATURITY MODEL
The Richardson Maturity Model
Level 2: HTTP verbs
http://martinfowler.com/articles/richardsonMaturityModel.html
leverage transport-native properties to enhance service
e.g., HTTP GET and PUT and DELETE and POST
Uses idiomatic HTTP controls like status codes, headers
HTTP VERBS
GET /users/21
DELETE /users/21
POST /users
PUT /users/21
retrieves a resource from a URI
removes the resource
creates a new record; returns a Location
updates a resource
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/</url-pattern>
<servlet-name>appServlet</servlet-name>
</filter-mapping>
STATUS CODES
status codes convey the result of the server’s attempt to
satisfy the request.
Categories:
1xx: informational
2xx: success
3xx: redirection
4xx: client error
5xx: server error
REST 101
200 OK - Everything worked
201 Created - Returns a Location header for new resource
202 Accepted - server has accepted the request, but it is not yet
complete. Status URI optionally conveyed in Location header
REST DESIGN WITH SPRINGREST 101
ACCEPTABLE
406:
NOT
REST 101
400 Bad Request - Malformed Syntax. Retry with change.
401 Unauthorized - authentication is required
403 Forbidden - server has understood, but refuses request
404 Not Found - server can’t find a resource for URI
406 Not Found - incompatible Accept headers specified
409 Conflict - resource conflicts with client request
REST 101
Clients and services must agree on a representation media type
through content negotiation.
Client specifies what it wants through Accept header
Server specifies what it produces through Content-Type header
REST 101
Spring MVC supports multiple types of content negotiation through its
ContentNegotiationStrategy:
e.g., Accept header, URL extension, request parameters, or a fixed type
Demonstration
Basic RESTful service, REST shells
HATEOAS
The Richardson Maturity Model
Level 3: Hypermedia Controls (aka, HATEOAS)
http://martinfowler.com/articles/richardsonMaturityModel.html
No a priori knowledge of service required
Navigation options are provided by service and hypermedia controls
Promotes longevity through a uniform interface
HATEOAS
Links provide possible navigations from a given resource
Links are dynamic, based on resource state.
<link href=“http://...:8080/users/232/customers”
rel= “customers”/>
Demonstration
Spring HATEOAS, Rest Shell
SPRING DATA REST
Spring Data REST simplifies the
generic data-centric @Controllers
Builds on top of Spring Data Repository support:
@RestResource (path = "users", rel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
	 User findByUsername(@Param ("username") String username);
SPRING DATA REST
Spring Data REST simplifies the
generic data-centric @Controllers
Builds on top of Spring Data Repository support:
@RestResource (path = "users", rel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
	 User findByUsername(@Param ("username") String username);
	
select u from User where u.username = ?
SPRING DATA REST
Spring Data REST simplifies the
generic data-centric @Controllers
Builds on top of Spring Data Repository support:
@RestResource (path = "users", rel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {

 List<User> findUsersByFirstNameOrLastNameOrUsername(
@Param ("firstName") String firstName,
@Param ("lastName") String lastName,
@Param ("username") String username);
}
SPRING DATA REST
Spring Data REST simplifies the
generic data-centric @Controllers
Builds on top of Spring Data Repository support:
@RestResource (path = "users", rel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {

 List<User> findUsersByFirstNameOrLastNameOrUsername(
@Param ("firstName") String firstName,
@Param ("lastName") String lastName,
@Param ("username") String username);
}
select u from User u
where u.username = ?
or u.firstName = ?
or u.lastName = ?
Demonstration
Spring Data, Spring Data REST
SECURITY
Security can be as simple, or complex, as you want...
If you can trust the client to keep a secret like a password:
...HTTP Basic if you have TLS
... HTTP Digest if you want extra security
OAUTH
Security can be as simple, or complex, as you want...
Can’t trust the client to keep a secret? (HTML page?)
Application has a user context and you don’t want clients to have a
user’s password?
...use OAuth
OAUTH
OAUTH
OAUTH
Demonstration
Spring Security OAuth
SPRING SOCIAL
Spring Social provides an authentication and
authorization client for OAuth (1.0, 1.0a, 2.0)
Provides type-safe API bindings for various services
BINDINGS...
...LOTS OF BINDINGS
Demonstration
Spring Social
SPRING ANDROID
Spring Social provides an authentication and
authorization client for OAuth (1.0, 1.0a, 2.0)
Provides type-safe API bindings for various services
SPRING ANDROID
Spring Android brings Spring core’s RestTemplate.
Spring Social and Spring HATEOAS work as well.
SPRING ANDROID
More than
500,000
activations
every day
More than
500,000
activations
every day
Demonstration
Spring Android-powered UI client
USING REST AND OAUTH FROM IOS
REST DESIGN WITH SPRING
iOS provides an HTTP client (NSURLConnection),
a JSON processor (NSJSONSerialization), and
a rich set of data structures (NSData, NSDictionary, and NSArray)
BASIC HTTP REQUEST
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil
error:nil];
BASIC HTTP REQUEST... IMPROVED
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSInteger status = [(NSHTTPURLResponse *)response statusCode];
if (status == 200 && data.length > 0 && error == nil)
{
// do something with data
}
ASYNCHRONOUS HTTP REQUESTS
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[NSURLConnection
sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *error)
{
NSInteger status = [(NSHTTPURLResponse *)response statusCode];
if (status == 200 && data.length > 0 && error == nil)
{
// do something with data
}
}
HTTP HEADERS
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"PUT"];
[request setValue:@"application/json"
forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json"
forHTTPHeaderField:@"Content-Type"];
[request setValue:contentLength
forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
JSON SERIALIZATION
// deserialize JSON data
NSError *error;
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
// serialize JSON data
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary
options:0
error:&error];
• HTTP Client
– NSURLConnection
• JSON Processor (iOS 5)
– NSJSONSerialization
• Data
– NSData
– NSDictionary
– NSArray
49
• Loading Data Synchronously
+ sendSynchronousRequest:returningResponse:error:
• Loading Data Asynchronously
+ sendAsynchronousRequest:queue:completionHandler:
50
51
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil
error:nil];
52
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSInteger status = [(NSHTTPURLResponse *)response statusCode];
if (status == 200 && data.length > 0 && error == nil)
{
// do something with data
}
53
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[NSURLConnection
sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *error)
{
NSInteger status = [(NSHTTPURLResponse *)response statusCode];
if (status == 200 && data.length > 0 && error == nil)
{
// do something with data
}
}
54
NSURL *url = [NSURL URLWithString:@"http://localhost"];
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"PUT"];
[request setValue:@"application/json"
forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json"
forHTTPHeaderField:@"Content-Type"];
[request setValue:contentLength
forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
55
// deserialize JSON data
NSError *error;
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
// serialize JSON data
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary
options:0
error:&error];
iOS Demo
Q&A
• Spring MVC Reference
http://static.springsource.org/spring-framework/docs/current/spring-framework-
reference/html/mvc.html
• URL Loading System Programming Guide
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/
URLLoadingSystem/URLLoadingSystem.html
• Ben Hale’s presentation at SpringOne 2GX
http://www.youtube.com/watch?v=wylViAqNiRA
58
• Spring Roo Beginning Guide
http://static.springsource.org/spring-roo/reference/html/
beginning.html#beginning-step-1
59
GREAT RESOURCES
Roy Fielding’s Dissertation introduces REST
http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_1%7C
The Spring REST Shell
http://github.com/jbrisbin/rest-shell
Spring Security, Security OAuth, Spring Data REST, HATEOAS, Social
http://github.com/SpringSource
Spring MVC Test Framework
http://static.springsource.org/spring-framework/docs/current/spring-framework-reference/
html/testing.html#spring-mvc-test-framework
GREAT RESOURCES
Oliver Gierke’s talk on Hypermedia from Øredev
@ http://vimeo.com/53214577
Lez Hazelwood’s talk on designing a beautiful JSON+REST API
Ben Hale’s talk on REST API design with Spring from SpringOne2GX 2012
@ http://www.youtube.com/watch?v=wylViAqNiRA
My links:
github.com/joshlong/the-spring-rest-stack
slideshare.net/joshlong/rest-apis-with-spring
@starbuxman
REST DESIGN WITH SPRING
Any
Questions?
@starbuxman | jlong@gopivotal.com | http://slideshare.net/joshlong
@royclarkson | rclarkson@gopivotal.com |http://www.slideshare.net/royclarkson
github.com/joshlong/the-spring-rest-stack

Contenu connexe

Tendances

Apache Sling as an OSGi-powered REST middleware
Apache Sling as an OSGi-powered REST middlewareApache Sling as an OSGi-powered REST middleware
Apache Sling as an OSGi-powered REST middlewareRobert Munteanu
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPressTaylor Lovett
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeVMware Tanzu
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreStormpath
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreStormpath
 
What's New in Spring 3.1
What's New in Spring 3.1What's New in Spring 3.1
What's New in Spring 3.1Matt Raible
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadAll Things Open
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and FriendsYun Zhi Lin
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
 
Using an API
Using an APIUsing an API
Using an APIAdam Culp
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsBastian Hofmann
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Maarten Balliauw
 
Effective Web Application Development with Apache Sling
Effective Web Application Development with Apache SlingEffective Web Application Development with Apache Sling
Effective Web Application Development with Apache SlingRobert Munteanu
 
Best practices for RESTful web service design
Best practices for RESTful web service designBest practices for RESTful web service design
Best practices for RESTful web service designRamin Orujov
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 

Tendances (20)

Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Apache Sling as an OSGi-powered REST middleware
Apache Sling as an OSGi-powered REST middlewareApache Sling as an OSGi-powered REST middleware
Apache Sling as an OSGi-powered REST middleware
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET Core
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
What's New in Spring 3.1
What's New in Spring 3.1What's New in Spring 3.1
What's New in Spring 3.1
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language Instead
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
Using an API
Using an APIUsing an API
Using an API
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
 
Effective Web Application Development with Apache Sling
Effective Web Application Development with Apache SlingEffective Web Application Development with Apache Sling
Effective Web Application Development with Apache Sling
 
Best practices for RESTful web service design
Best practices for RESTful web service designBest practices for RESTful web service design
Best practices for RESTful web service design
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 

Similaire à Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAnuchit Chalothorn
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Restful webservices
Restful webservicesRestful webservices
Restful webservicesKong King
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all detailsgogijoshiajmer
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJerry Kurian
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSUFYAN SATTAR
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp ConceptDian Aditya
 

Similaire à Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson (20)

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all details
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with Java
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
RESTFul WebApp Concept
RESTFul WebApp ConceptRESTFul WebApp Concept
RESTFul WebApp Concept
 

Plus de Joshua Long

Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring BootJoshua Long
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring BootJoshua Long
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 updateJoshua Long
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update finalJoshua Long
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryJoshua Long
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud FoundryJoshua Long
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloudJoshua Long
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeJoshua Long
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom Joshua Long
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with SpringJoshua Long
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the ScenesJoshua Long
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampJoshua Long
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundryJoshua Long
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenJoshua Long
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom UsageJoshua Long
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC ModelJoshua Long
 

Plus de Joshua Long (20)

Bootiful Code with Spring Boot
Bootiful Code with Spring BootBootiful Code with Spring Boot
Bootiful Code with Spring Boot
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
the Spring 4 update
the Spring 4 updatethe Spring 4 update
the Spring 4 update
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update final
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Integration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud FoundryIntegration and Batch Processing on Cloud Foundry
Integration and Batch Processing on Cloud Foundry
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundry
 
Spring in-the-cloud
Spring in-the-cloudSpring in-the-cloud
Spring in-the-cloud
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - EuropeThe Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom
 
Multi client Development with Spring
Multi client Development with SpringMulti client Development with Spring
Multi client Development with Spring
 
Spring Batch Behind the Scenes
Spring Batch Behind the ScenesSpring Batch Behind the Scenes
Spring Batch Behind the Scenes
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Spring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud FoundrySpring in the Cloud - using Spring with Cloud Foundry
Spring in the Cloud - using Spring with Cloud Foundry
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in HeavenSpring and Cloud Foundry; a Marriage Made in Heaven
Spring and Cloud Foundry; a Marriage Made in Heaven
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Using Spring's IOC Model
Using Spring's IOC ModelUsing Spring's IOC Model
Using Spring's IOC Model
 

Dernier

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Dernier (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson

  • 1. © 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Building Smart Clients with Spring by Josh Long and Roy Clarkson
  • 2. WHAT IS REST? REST is an architectural constraint based on HTTP 1.1, and created as part of Roy Fielding’s doctoral dissertation in 2000. It embraces HTTP. It’s a style, not a standard http://en.wikipedia.org/wiki/Representational_state_transfer
  • 3. WHAT IS REST? REST has no hard and fast rules. REST is an architectural style, not a standard. REST uses Headers to describe requests & responses REST embraces HTTP verbs
  • 4. HTTP VERBS GET /users/21 GET requests retrieve information. GET can have side-effects (but it’s unexpected) GET can be conditional, or partial: If-Modified-Since, Range
  • 5. HTTP VERBS DELETE requests that a resource be removed, though the deletion doesn’t have to be immediate. DELETE /users/21
  • 6. HTTP VERBS POST requests that the resource do something with the enclosed entity POST can be used to create or update. POST /users { “firstName”: “Juergen” }
  • 7. HTTP VERBS PUT requests that the entity be stored at a URI PUT can be used to create or update. PUT /users/21 { “firstName”: “Juergen” }
  • 8. THE MATURITY MODEL The Richardson Maturity Model is a way to grade your API according to the REST constraints with 4 levels of increasing compliance http://martinfowler.com/articles/richardsonMaturityModel.html
  • 9. THE MATURITY MODEL The Richardson Maturity Model Level 0: swamp of POX http://martinfowler.com/articles/richardsonMaturityModel.html Uses HTTP mainly as a tunnel through one URI e.g., SOAP, XML-RPC Usually features on HTTP verb (POST)
  • 10. THE MATURITY MODEL The Richardson Maturity Model Level 1: resources http://martinfowler.com/articles/richardsonMaturityModel.html Multiple URIs to distinguish related nouns e.g., /articles/1, /articles/2, vs. just /articles
  • 11. THE MATURITY MODEL The Richardson Maturity Model Level 2: HTTP verbs http://martinfowler.com/articles/richardsonMaturityModel.html leverage transport-native properties to enhance service e.g., HTTP GET and PUT and DELETE and POST Uses idiomatic HTTP controls like status codes, headers
  • 12. HTTP VERBS GET /users/21 DELETE /users/21 POST /users PUT /users/21 retrieves a resource from a URI removes the resource creates a new record; returns a Location updates a resource <filter> <filter-name>hiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/</url-pattern> <servlet-name>appServlet</servlet-name> </filter-mapping>
  • 13. STATUS CODES status codes convey the result of the server’s attempt to satisfy the request. Categories: 1xx: informational 2xx: success 3xx: redirection 4xx: client error 5xx: server error
  • 14. REST 101 200 OK - Everything worked 201 Created - Returns a Location header for new resource 202 Accepted - server has accepted the request, but it is not yet complete. Status URI optionally conveyed in Location header
  • 15. REST DESIGN WITH SPRINGREST 101 ACCEPTABLE 406: NOT
  • 16. REST 101 400 Bad Request - Malformed Syntax. Retry with change. 401 Unauthorized - authentication is required 403 Forbidden - server has understood, but refuses request 404 Not Found - server can’t find a resource for URI 406 Not Found - incompatible Accept headers specified 409 Conflict - resource conflicts with client request
  • 17. REST 101 Clients and services must agree on a representation media type through content negotiation. Client specifies what it wants through Accept header Server specifies what it produces through Content-Type header
  • 18. REST 101 Spring MVC supports multiple types of content negotiation through its ContentNegotiationStrategy: e.g., Accept header, URL extension, request parameters, or a fixed type
  • 20. HATEOAS The Richardson Maturity Model Level 3: Hypermedia Controls (aka, HATEOAS) http://martinfowler.com/articles/richardsonMaturityModel.html No a priori knowledge of service required Navigation options are provided by service and hypermedia controls Promotes longevity through a uniform interface
  • 21. HATEOAS Links provide possible navigations from a given resource Links are dynamic, based on resource state. <link href=“http://...:8080/users/232/customers” rel= “customers”/>
  • 23. SPRING DATA REST Spring Data REST simplifies the generic data-centric @Controllers Builds on top of Spring Data Repository support: @RestResource (path = "users", rel = "users") public interface UserRepository extends PagingAndSortingRepository<User, Long> { User findByUsername(@Param ("username") String username);
  • 24. SPRING DATA REST Spring Data REST simplifies the generic data-centric @Controllers Builds on top of Spring Data Repository support: @RestResource (path = "users", rel = "users") public interface UserRepository extends PagingAndSortingRepository<User, Long> { User findByUsername(@Param ("username") String username); select u from User where u.username = ?
  • 25. SPRING DATA REST Spring Data REST simplifies the generic data-centric @Controllers Builds on top of Spring Data Repository support: @RestResource (path = "users", rel = "users") public interface UserRepository extends PagingAndSortingRepository<User, Long> { List<User> findUsersByFirstNameOrLastNameOrUsername( @Param ("firstName") String firstName, @Param ("lastName") String lastName, @Param ("username") String username); }
  • 26. SPRING DATA REST Spring Data REST simplifies the generic data-centric @Controllers Builds on top of Spring Data Repository support: @RestResource (path = "users", rel = "users") public interface UserRepository extends PagingAndSortingRepository<User, Long> { List<User> findUsersByFirstNameOrLastNameOrUsername( @Param ("firstName") String firstName, @Param ("lastName") String lastName, @Param ("username") String username); } select u from User u where u.username = ? or u.firstName = ? or u.lastName = ?
  • 28. SECURITY Security can be as simple, or complex, as you want... If you can trust the client to keep a secret like a password: ...HTTP Basic if you have TLS ... HTTP Digest if you want extra security
  • 29. OAUTH Security can be as simple, or complex, as you want... Can’t trust the client to keep a secret? (HTML page?) Application has a user context and you don’t want clients to have a user’s password? ...use OAuth
  • 30. OAUTH
  • 31. OAUTH
  • 32. OAUTH
  • 34. SPRING SOCIAL Spring Social provides an authentication and authorization client for OAuth (1.0, 1.0a, 2.0) Provides type-safe API bindings for various services
  • 38. SPRING ANDROID Spring Social provides an authentication and authorization client for OAuth (1.0, 1.0a, 2.0) Provides type-safe API bindings for various services
  • 39. SPRING ANDROID Spring Android brings Spring core’s RestTemplate. Spring Social and Spring HATEOAS work as well.
  • 40. SPRING ANDROID More than 500,000 activations every day More than 500,000 activations every day
  • 42. USING REST AND OAUTH FROM IOS
  • 43. REST DESIGN WITH SPRING iOS provides an HTTP client (NSURLConnection), a JSON processor (NSJSONSerialization), and a rich set of data structures (NSData, NSDictionary, and NSArray)
  • 44. BASIC HTTP REQUEST NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  • 45. BASIC HTTP REQUEST... IMPROVED NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSURLResponse *response; NSError *error; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSInteger status = [(NSHTTPURLResponse *)response statusCode]; if (status == 200 && data.length > 0 && error == nil) { // do something with data }
  • 46. ASYNCHRONOUS HTTP REQUESTS NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSInteger status = [(NSHTTPURLResponse *)response statusCode]; if (status == 200 && data.length > 0 && error == nil) { // do something with data } }
  • 47. HTTP HEADERS NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"PUT"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData];
  • 48. JSON SERIALIZATION // deserialize JSON data NSError *error; NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // serialize JSON data NSError *error; NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
  • 49. • HTTP Client – NSURLConnection • JSON Processor (iOS 5) – NSJSONSerialization • Data – NSData – NSDictionary – NSArray 49
  • 50. • Loading Data Synchronously + sendSynchronousRequest:returningResponse:error: • Loading Data Asynchronously + sendAsynchronousRequest:queue:completionHandler: 50
  • 51. 51 NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  • 52. 52 NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSURLResponse *response; NSError *error; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSInteger status = [(NSHTTPURLResponse *)response statusCode]; if (status == 200 && data.length > 0 && error == nil) { // do something with data }
  • 53. 53 NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSInteger status = [(NSHTTPURLResponse *)response statusCode]; if (status == 200 && data.length > 0 && error == nil) { // do something with data } }
  • 54. 54 NSURL *url = [NSURL URLWithString:@"http://localhost"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"PUT"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:contentLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData];
  • 55. 55 // deserialize JSON data NSError *error; NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // serialize JSON data NSError *error; NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
  • 57. Q&A
  • 58. • Spring MVC Reference http://static.springsource.org/spring-framework/docs/current/spring-framework- reference/html/mvc.html • URL Loading System Programming Guide http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ URLLoadingSystem/URLLoadingSystem.html • Ben Hale’s presentation at SpringOne 2GX http://www.youtube.com/watch?v=wylViAqNiRA 58
  • 59. • Spring Roo Beginning Guide http://static.springsource.org/spring-roo/reference/html/ beginning.html#beginning-step-1 59
  • 60. GREAT RESOURCES Roy Fielding’s Dissertation introduces REST http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_1%7C The Spring REST Shell http://github.com/jbrisbin/rest-shell Spring Security, Security OAuth, Spring Data REST, HATEOAS, Social http://github.com/SpringSource Spring MVC Test Framework http://static.springsource.org/spring-framework/docs/current/spring-framework-reference/ html/testing.html#spring-mvc-test-framework
  • 61. GREAT RESOURCES Oliver Gierke’s talk on Hypermedia from Øredev @ http://vimeo.com/53214577 Lez Hazelwood’s talk on designing a beautiful JSON+REST API Ben Hale’s talk on REST API design with Spring from SpringOne2GX 2012 @ http://www.youtube.com/watch?v=wylViAqNiRA My links: github.com/joshlong/the-spring-rest-stack slideshare.net/joshlong/rest-apis-with-spring @starbuxman
  • 62. REST DESIGN WITH SPRING Any Questions? @starbuxman | jlong@gopivotal.com | http://slideshare.net/joshlong @royclarkson | rclarkson@gopivotal.com |http://www.slideshare.net/royclarkson github.com/joshlong/the-spring-rest-stack