SlideShare a Scribd company logo
© 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

More Related Content

What's hot (20)

PDF
Spring Mvc Rest
Craig Walls
 
PDF
Apache Sling as an OSGi-powered REST middleware
Robert Munteanu
 
PPTX
The JSON REST API for WordPress
Taylor Lovett
 
PPTX
The Past Year in Spring for Apache Geode
VMware Tanzu
 
PPTX
Building Your First App with MongoDB
MongoDB
 
PDF
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
PPTX
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
PDF
Spring Web Services: SOAP vs. REST
Sam Brannen
 
PDF
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
PDF
What's New in Spring 3.1
Matt Raible
 
PDF
Regex Considered Harmful: Use Rosie Pattern Language Instead
All Things Open
 
PDF
Dropwizard and Friends
Yun Zhi Lin
 
ODP
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Masoud Kalali
 
PPTX
Android and REST
Roman Woźniak
 
PDF
Using an API
Adam Culp
 
PDF
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
PPTX
Sherlock Homepage - A detective story about running large web services - NDC ...
Maarten Balliauw
 
PDF
Effective Web Application Development with Apache Sling
Robert Munteanu
 
PPTX
Best practices for RESTful web service design
Ramin Orujov
 
PDF
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
Spring Mvc Rest
Craig Walls
 
Apache Sling as an OSGi-powered REST middleware
Robert Munteanu
 
The JSON REST API for WordPress
Taylor Lovett
 
The Past Year in Spring for Apache Geode
VMware Tanzu
 
Building Your First App with MongoDB
MongoDB
 
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
Best Practices for Architecting a Pragmatic Web API.
Mario Cardinal
 
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
What's New in Spring 3.1
Matt Raible
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
All Things Open
 
Dropwizard and Friends
Yun Zhi Lin
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Masoud Kalali
 
Android and REST
Roman Woźniak
 
Using an API
Adam Culp
 
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Maarten Balliauw
 
Effective Web Application Development with Apache Sling
Robert Munteanu
 
Best practices for RESTful web service design
Ramin Orujov
 
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 

Similar to Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson (20)

PDF
building-rest-api-with-spring-boot-in28minutes-presentation.pdf
HarshitRaj774201
 
PPTX
RESTful Web Services
Gordon Dickens
 
PPTX
Rest presentation
srividhyau
 
PPTX
Rest WebAPI with OData
Mahek Merchant
 
PDF
Spring MVC to iOS and the REST
Roy Clarkson
 
PDF
Facebook & Twitter API
Fabrice Delhoste
 
PPTX
REST Methodologies
jrodbx
 
PDF
Microservices with Spring Boot
Joshua Long
 
PPTX
Pragmatic REST APIs
amesar0
 
PPTX
Spring Test Framework
GlobalLogic Ukraine
 
PDF
REST Api with Asp Core
Irina Scurtu
 
PDF
Android App Development 06 : Network &amp; Web Services
Anuchit Chalothorn
 
PPT
RESTful SOA - 中科院暑期讲座
Li Yi
 
PDF
What is REST?
Saeid Zebardast
 
PPTX
rest-api-basics.pptx
AgungSutikno1
 
PDF
CDI, Seam & RESTEasy: You haven't seen REST yet!
Dan Allen
 
PPTX
JAX-RS. Developing RESTful APIs with Java
Jerry Kurian
 
PPTX
Tutorial_Rest_API_For_Beginners_125.pptx
T.Choithram & Sons Dubai
 
PPTX
Rest APIs Training
Shekhar Kumar
 
PPTX
L18 REST API Design
Ólafur Andri Ragnarsson
 
building-rest-api-with-spring-boot-in28minutes-presentation.pdf
HarshitRaj774201
 
RESTful Web Services
Gordon Dickens
 
Rest presentation
srividhyau
 
Rest WebAPI with OData
Mahek Merchant
 
Spring MVC to iOS and the REST
Roy Clarkson
 
Facebook & Twitter API
Fabrice Delhoste
 
REST Methodologies
jrodbx
 
Microservices with Spring Boot
Joshua Long
 
Pragmatic REST APIs
amesar0
 
Spring Test Framework
GlobalLogic Ukraine
 
REST Api with Asp Core
Irina Scurtu
 
Android App Development 06 : Network &amp; Web Services
Anuchit Chalothorn
 
RESTful SOA - 中科院暑期讲座
Li Yi
 
What is REST?
Saeid Zebardast
 
rest-api-basics.pptx
AgungSutikno1
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
Dan Allen
 
JAX-RS. Developing RESTful APIs with Java
Jerry Kurian
 
Tutorial_Rest_API_For_Beginners_125.pptx
T.Choithram & Sons Dubai
 
Rest APIs Training
Shekhar Kumar
 
L18 REST API Design
Ólafur Andri Ragnarsson
 
Ad

More from Joshua Long (20)

PDF
Bootiful Code with Spring Boot
Joshua Long
 
PDF
REST APIs with Spring
Joshua Long
 
PDF
the Spring 4 update
Joshua Long
 
PDF
The spring 32 update final
Joshua Long
 
KEY
Multi Client Development with Spring
Joshua Long
 
KEY
Integration and Batch Processing on Cloud Foundry
Joshua Long
 
KEY
using Spring and MongoDB on Cloud Foundry
Joshua Long
 
PDF
Spring in-the-cloud
Joshua Long
 
KEY
Multi Client Development with Spring
Joshua Long
 
KEY
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
Joshua Long
 
KEY
A Walking Tour of (almost) all of Springdom
Joshua Long
 
KEY
Multi client Development with Spring
Joshua Long
 
KEY
Spring Batch Behind the Scenes
Joshua Long
 
KEY
Cloud Foundry Bootcamp
Joshua Long
 
KEY
Spring in the Cloud - using Spring with Cloud Foundry
Joshua Long
 
PPT
Spring and Cloud Foundry; a Marriage Made in Heaven
Joshua Long
 
PPT
Spring 3.1: a Walking Tour
Joshua Long
 
PDF
Extending Spring for Custom Usage
Joshua Long
 
PPT
Using Spring's IOC Model
Joshua Long
 
PPT
Enterprise Integration and Batch Processing on Cloud Foundry
Joshua Long
 
Bootiful Code with Spring Boot
Joshua Long
 
REST APIs with Spring
Joshua Long
 
the Spring 4 update
Joshua Long
 
The spring 32 update final
Joshua Long
 
Multi Client Development with Spring
Joshua Long
 
Integration and Batch Processing on Cloud Foundry
Joshua Long
 
using Spring and MongoDB on Cloud Foundry
Joshua Long
 
Spring in-the-cloud
Joshua Long
 
Multi Client Development with Spring
Joshua Long
 
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
Joshua Long
 
A Walking Tour of (almost) all of Springdom
Joshua Long
 
Multi client Development with Spring
Joshua Long
 
Spring Batch Behind the Scenes
Joshua Long
 
Cloud Foundry Bootcamp
Joshua Long
 
Spring in the Cloud - using Spring with Cloud Foundry
Joshua Long
 
Spring and Cloud Foundry; a Marriage Made in Heaven
Joshua Long
 
Spring 3.1: a Walking Tour
Joshua Long
 
Extending Spring for Custom Usage
Joshua Long
 
Using Spring's IOC Model
Joshua Long
 
Enterprise Integration and Batch Processing on Cloud Foundry
Joshua Long
 
Ad

Recently uploaded (20)

PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 

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 | [email protected] | http://slideshare.net/joshlong @royclarkson | [email protected] |http://www.slideshare.net/royclarkson github.com/joshlong/the-spring-rest-stack