Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

REST Architectural Style: A Detail Explain
Cao Duc Nguyen
nguyen.cao-duc@hp.com
Software Designer

April 26, 2012
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Outline

1

Introduction
Web APIs

2

REST Fundamentals
HTTP
REST

3

Java Open Source RESTful Web Services
Specification
Implementation

4

Conclusion
Discussion
Final word

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Web APIs

The Importance of APIs in Web Development

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Web APIs

APIs Timeline on ProgrammableWeb

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Web APIs

APIs Timeline on ProgrammableWeb in more details

Conclusion
Introduction

REST Fundamentals

Web APIs

Featured APIs & Mashups

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Web APIs

APIs protocols & styles

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

HTTP

REST is an architectural style
Gorthic Architectural Style

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

HTTP

REST v.s HTTP

Gorthic architectural style

REST

HTTP

Conclusion
Introduction

REST Fundamentals

HTTP

Client/Server Model

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

HTTP

HTTP is resource-centric

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

HTTP

Resource Identifier, Methods & Representations

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

HTTP

Hypermedia: Association & Composition

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

HTTP

HTTP Methods in more details
GET

Safe, Idempotent, Cacheable

PUT

Idempotent

DELETE

Idempotent

HEAD

Safe, Idempotent

OPTIONS

Safe, Idempotent

POST
Safe The client did not request any side-effects on
server other than data retrieval.
Idempotent Any side-effects on the server of several identical
idempotent methods are the same as the
side-effects of one single method.
Cacheable Explain in more details later. . .
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

HTTP

Intermediaries - Cache
A new request for a cached resource can be returned
immediately by intermediary caches.

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

HTTP

Intermediaries - Proxy & Gateway

Proxy
an intermediary selected by a client, to provide
interfaces to services like data translation,
performance enhancement, or security protection.
Gateway
an intermediary imposed by the network or origin
server to provide an interface encapsulation of
other services, for data translation, performance
enhancement, or security enforcement.
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

HTTP

Stateless

HTTP Requests are stateless, which means each request is
independent from the others.
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

HTTP

Stateless

HTTP Requests are stateless, which means each request is
independent from the others.
intermediaries only need to work on a single interaction
without knowing the entire topology
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

REST

REST Architectural Style

REpresentational State Transfer
The representation returned by the server places
or transfers the client from state to state.
REST Architectural Style
. . . a set of architectural constraints that, when
applied as a whole, emphasizes scalability of
component interactions, generality of interfaces,
independent deployment of components,
intermediary components to reduce interaction
latency, enforce security, and encapsulate legacy
systems.
Roy T. Fielding
Introduction

REST Fundamentals

REST

REST Architectural Constraints

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

REST

REST Architectural Elements

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

REST

RESTful v.s SOAP

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Specification

JAX-RS: The Java™API for RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

Specification

JAX-RS Hello Example
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/hello/{username}")
public class Hello {
private String name="no-one";
@GET
@Produces("text/plain")
public String hello(@PathParam("username")
String userName) {
userName = userName==null?name:userName;
return " Hello, "+userName;
}
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

Specification

JAX-RS Hello Example

@POST
@Consumes("text/plain")
public String hello(@FormParam("username")
String userName) {
name = userName==null?name:userName;
return " Hello, "+userName;
}
}
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Conclusion

Implementation

Open Sources RESTful Web Service Implementation of JAX-RS

Jersey - Sun reference implementation
RESTEasy - JBoss
Restlet
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Discussion

REST Motivation

Scalability
Perfomance
Reduce Payload & Latency
Dynamic Component Connectors

Conclusion
Introduction

REST Fundamentals

Discussion

REST v.s the rest

SOA ?
Servlet & JSP ?
Javascript ?

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Final word

Web APIs Worldwide

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Final word

Web APIs Featured Regions

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Final word

Web APIs Vietnam

Java Open Source RESTful Web Services

Conclusion
Introduction

REST Fundamentals

Java Open Source RESTful Web Services

Final word

THANK YOU *-*

Conclusion

REST Architectural Style: A Detail Explain