SlideShare a Scribd company logo
1 of 75
Real world RESTful service development 
problems and solutions 
by Bhakti Mehta 
@bhakti_mehta
Introduction 
 Senior Staff Engineer at Blue Jeans Network 
 Worked at Sun Microsystems/Oracle for 13 years 
 Committer to numerous open source projects 
including GlassFish Open Source Application Server 
Copyright 2014 Bhakti Mehta All rights reserved 
2
My latest book 
Copyright 2014 Bhakti Mehta All rights reserved 
3
Previous book 
Copyright 2014 Bhakti Mehta All rights reserved 
4
What you will learn 
 REST architectural style 
 Goals of REST 
 Design principles for REST 
 Advanced topics 
 Emerging standards and REST 
Copyright 2014 Bhakti Mehta All rights reserved 
5
What is REST? 
 All resources are identified by the URIs. 
 All resources can have multiple representations 
 All resources can be 
accessed/modified/created/deleted by standard 
HTTP methods. 
 There is no state information on the server. 
Copyright 2014 Bhakti Mehta All rights reserved 
6
Why REST? 
 Mature architectural style 
 Ease of use 
 Statelessness improves 
 Visibility 
 Reliability 
 Performance 
 Age of applications 
Copyright 2014 Bhakti Mehta All rights reserved 
7
Java API for RESTful Services 
 Standardized API as part of platform to build 
RESTful Services 
 Convert POJOs to RESTful Web Services using 
Annotations 
 Support for various representations 
 Improved support for client APIs 
Copyright 2014 Bhakti Mehta All rights reserved 
8
Design principles for building RESTful Services 
 Identify the resource URIs. 
 Identify the different representations supported by 
the resource 
 Implement the RESTful services using JAX-RS APIs 
 Deploy the RESTful services 
 Test the RESTful services 
Copyright 2014 Bhakti Mehta All rights reserved 
9
Resource URI patterns 
 Nouns representing a resource 
 Verbs representing an action on the resource 
 Safety 
 Idempotence 
Copyright 2014 Bhakti Mehta All rights reserved 
10
URI representation of a resource 
/v1/coffees 
To represent all the coffees that are sold by a coffee shop 
/v1/coffees/orders 
To represent all the coffees that are ordered 
/v1/coffees/orders/123 
To represent a single coffee order of coffee identified by 
“123” 
/v1/users/5034/books 
To represent all the books for a user identified by “5034” 
Copyright 2014 Bhakti Mehta All rights reserved 
11
HTTP verbs and REST 
 GET 
 PUT 
 POST 
 DELETE 
 HEAD 
Copyright 2014 Bhakti Mehta All rights reserved 
12
HTTP verbs and actions 
GET v1/library/books 
Gets a list of books 
POST v1/library/books 
Creates a new book order 
DELETE v1/library/books/isbn/12345678 
Deletes a book identified by ISBN “12345678” 
PUT v1/library/books/isbn/12345678 
Updates a specific book identified by ISBN “12345678’ 
Copyright 2014 Bhakti Mehta All rights reserved 
13
Safety and Idepotence 
 Safe methods 
 Safe methods are methods that do not change the state on the 
server. 
 For example GET is a safe method. 
 Idempotent methods 
 This method produce the same results irrespective of how 
many times it is called. 
 For example GET, PUT and DELETE are idempotent 
Copyright 2014 Bhakti Mehta All rights reserved 
14
PUT vs POST 
 PUT vs POST 
 So POST /v1/coffees/orders means to create a new 
resource and return an identifier to describe the resource 
 In contrast PUT /v1/coffees/orders/1234 means to 
update a resource identified by “1234” if it exists else 
create a new order and use the URI orders/1234 to 
identify it. 
 PUT and POST can both be used to create or update 
methods. The usage of the method depends on the 
idempotence behavior expected from the method as well 
the location of the resource to identify it. 
Copyright 2014 Bhakti Mehta All rights reserved 
15
Best practices for RESTful resources 
 The API developer should use nouns to understand 
and navigate through resources 
 Use associations in the URIs to identify sub 
resources. For user/1234/books/5678/authors. 
 For specific variations use query parameters. For 
example to get all the books with 10 reviews 
/user/1234/books?reviews_counts=10 
Copyright 2014 Bhakti Mehta All rights reserved 
16
Best practices for RESTful resources 
 Have defaults for the output format for the response 
 Have camelCase or use _ for attribute names. 
 Support a standard API for count for example 
users/1234/books/count 
 Support a pretty printing option 
users/1234?pretty_print. 
Copyright 2014 Bhakti Mehta All rights reserved 
17
Richardson Maturity Model 
Copyright 2014 Bhakti Mehta All rights reserved 
18
Richardson Maturity Model 
 Level 0 – Remote Procedure Invocation 
 SOAP or XML RPC and POX with POST 
 Level 1 – REST resources 
 POST with REST URIs 
 Level 2 – More HTTP Verbs 
 Verbs like GET, HEAD, PUT, DELETE 
 Level 3 – HATEOAS 
 Responses contain more details to help client take next action 
Copyright 2014 Bhakti Mehta All rights reserved 
19
REST architectural blocks 
Copyright 2014 Bhakti Mehta All rights reserved 
20
Content Negotiation 
 The process of selecting the best representation for a 
given response when there are multiple 
representations available. 
 Typical responses can be from 
 JSON 
 XML 
 TEXT 
 etc 
Copyright 2014 Bhakti Mehta All rights reserved 
21
Content Negotiation 
 Using HTTP headers 
 The Content-Type HTTP header is used to indicate the mime 
type of the entity being sent by the server 
 A client can make a request to the server and specify what 
media types it can handle and what is its order of preference as 
part of the “Accept” HTTP header. 
Copyright 2014 Bhakti Mehta All rights reserved 
22
Content Negotiation 
 Using URL patterns 
 Using resource representation based on extension of 
a resource in the URL. 
 For example a client can ask for details using 
http://foo.api.com/v2/library/books.xml 
orhttp://foo.api.com/v2/library/books.json 
Copyright 2014 Bhakti Mehta All rights reserved 
23
Content Negotiation and JAX-RS 
javax.ws.rs.Produces 
javax.ws.rs.Consumes 
@POST 
@Consumes(MediaType.APPLICATION_JSON) 
@Produces(MediaType.APPLICATION_JSON) 
public Response addCoffee(Coffee coffee) { 
// Implementation here 
} 
Copyright 2014 Bhakti Mehta All rights reserved 
24
Versioning 
 For evolution of the application 
 It is hard to foresee all the resources, which will 
change over the life of the application. 
 The API developers must ensure that the HTTP verbs 
semantics and status codes should continue to work 
without human intervention as the version changes. 
Copyright 2014 Bhakti Mehta All rights reserved 
25
API versioning strategies 
 Specify the version in the URI itself. 
 Specify the version in the request query parameter 
 Specify the version in the Accept header 
Copyright 2014 Bhakti Mehta All rights reserved 
26
Version in the URI 
 For example http://api.foo.com/v2/coffees/1234 
 Additionally API developers can provide a path, 
which defaults to the latest version of the API. Thus 
the following request URI's should behave identically 
 http://api.foo.com/coffees/1234 
http://api.foo.com/v2/coffees/1234 
Copyright 2014 Bhakti Mehta All rights reserved 
27
Version in request query parameter 
 For example in the following URL v2 has been 
specified as part of the query parameter, ?version=v2 
 http://api.foo.com/coffees/1234?version=v2 
Copyright 2014 Bhakti Mehta All rights reserved 
28
Version as part of mime type 
 Some APIs prefer to put version as part of the 
“Accept” header 
 For example Accept: application/vnd.foo-v1+json 
 In the above snippet vnd stands for vendor specific 
mime type. 
 GitHub uses this format 
Copyright 2014 Bhakti Mehta All rights reserved 
29
Case studies for versioning 
 Facebook, Twitter, Stripe API all use versions as part 
of the URI. 
Facebook API makes a version unusable two years 
after the date that the subsequent version is released. 
If a client makes a un-versioned call, the server will 
default to the oldest available version of the 
Facebook API. 
 Twitter API, provides a six months to completely 
transition from v1.0 from v1.1 
Copyright 2014 Bhakti Mehta All rights reserved 
30
Specifying version in the Accept header 
 For example Accept: application/vnd.foo-v1+json 
 In the above snippet vnd stands for vendor specific 
mime type. This removes the version for the URL 
and is preferred by some API developers. 
Copyright 2014 Bhakti Mehta All rights reserved 
31
Error handling and Response codes 
 HTTP provides standardized response codes that can 
be returned for every request. 
 It is a good practice to not show a stack trace as part 
of the response 
 Use response codes to identify client or server side 
errors appropriately 
Copyright 2014 Bhakti Mehta All rights reserved 
32
REST response codes 
Group Response code Description 
Success 2XX 200 OK Used with PUT or 
POST or DELETE. It 
returns content as part 
of the response 
201 Created used when creating a 
resource with PUT. It 
must contain the 
Location header of the 
resource. 
204 No Content used for DELETE, 
POST or PUT 
operation. No content 
is returned as part of 
the response. 
Copyright 2014 Bhakti Mehta All rights reserved 
33
REST response codes 
Group Response code Description 
Success 2XX 202 Accepted Send response 
later as processing 
has not been 
completed as yet. 
Redirectional 3XX 301 Permanent All requests are 
directed to new 
location. 
302 Found Resource is valid 
and exists 
Copyright 2014 Bhakti Mehta All rights reserved 
34
REST response codes 
Group Response code Description 
Client Error 4XX 401 Unauthorized Cannot process the 
request based on 
credentials 
404 Not Found Resource is not 
found 
Server Errors 5xx 500 Internal 
Server Error 
Generic message 
when no specific 
exceptions are 
available 
Copyright 2014 Bhakti Mehta All rights reserved 
35
JAX-RS and Response codes 
JAX-RS defines a javax.ws.rs.core.Response class, 
which has static methods to create an instance using 
javax.ws.rs.core.Response.ResponseBuilder 
@POST 
Response addCoffee(...) { 
Coffee coffee = ... 
URI coffeeId = UriBuilder.fromResource(Coffee.class)... 
return Response.created(coffeeId).build(); 
} 
Copyright 2014 Bhakti Mehta All rights reserved 
36
Logging REST API 
 Complex distributed applications can introduce 
many points of failure 
 Logging is a very important aspect of building 
RESTful services especially in the case of debugging 
production issues in distributed nodes running 
various micro services. 
 It helps to link events or transactions between the 
various components that make an application or a 
business service. 
Copyright 2014 Bhakti Mehta All rights reserved 
37
Logging REST API best practices 
 Including a detailed consistent pattern across service 
logs 
 Obfuscating sensitive data 
 Identifying the caller or the initiator as part of the 
logs 
 Do not log payloads by default 
Copyright 2014 Bhakti Mehta All rights reserved 
38
Case studies of logging frameworks in distributed 
environments 
 Facebook has developed a homegrown solution 
called Scribe, which is a server for aggregating 
streaming log data. 
 Dapper is Google's tracing system, which samples 
data from the thousands of requests and provides 
sufficient information to trace data. Traces are 
collected in local log files and then pulled in Google's 
BigTable database. 
Copyright 2014 Bhakti Mehta All rights reserved 
39
Caching 
 Storing response information related to the requests 
in a temporary storage for a specific period of time. 
 Ensures that the server is not burdened with 
processing those requests in future when the 
responses can be fulfilled from the cache. 
Copyright 2014 Bhakti Mehta All rights reserved 
40
Caching Patterns 
 Types of Caching Headers 
 Strong Caching Headers 
 Weak Caching Headers 
Copyright 2014 Bhakti Mehta All rights reserved 
41
Strong Caching Headers 
 Cache-Control 
 Expires 
 The Expires and Cache-Control headers specify the 
time period during which the browser can use the 
cached resource without checking for a newer 
version. 
 Cache-Control max-age takes the time 
 Expires takes a date 
Copyright 2014 Bhakti Mehta All rights reserved 
42
Weak Caching Headers 
 ETag 
 Last-Modified 
 These headers enable the browser to check if the 
resource has changed since the last GET request. In 
the Last-Modified header, there is a date associated 
with the modification of the resource. In the ETag 
header, there can be any value that uniquely 
identifies a resource (like a hash). 
Copyright 2014 Bhakti Mehta All rights reserved 
43
JAX-RS and Caching headers 
@GET 
@Path("{order}") 
@Produces(MediaType.APPLICATION_XML) 
@NotNull(message = "Coffee does not exist for the order id 
requested") 
public Response getCoffee(@PathParam("order") int order) { 
Coffee coffee = CoffeeService.getCoffee(order); 
CacheControl cacheControl = new CacheControl(); 
cacheControl.setMaxAge(3600); 
cacheControl.setPrivate(true); 
Response.ResponseBuilder responseBuilder = 
Response.ok(coffee); 
responseBuilder.cacheControl(cacheControl); 
return responseBuilder.build(); 
} 
Copyright 2014 Bhakti Mehta All rights reserved 
44
Caching best practices 
 It is a good practice to specify either Expires or 
Cache-Control max-age along with one of the two 
Last-Modified and ETag headers in the HTTP 
response. Sending both Expires and Cache-Control 
max-age is redundant. Similarly, sending both Last- 
Modified and ETag is redundant 
Copyright 2014 Bhakti Mehta All rights reserved 
45
Caching best practices 
 Cache on GET request 
 Invalidate cache on PUT, POST or DELETE 
 Periodically purge cache entries 
Copyright 2014 Bhakti Mehta All rights reserved 
46
Asynchronous and long running jobs in REST 
 A common pattern in developing RESTful API is to 
deal with asynchronous and long running jobs. 
 API developers need to create resources that might 
take a considerable amount of time 
 They cannot have the clients wait on the API to 
finish. 
Copyright 2014 Bhakti Mehta All rights reserved 
47
Asynchronous and long running jobs 
 Server side: 
 AsyncResponse 
 @Suspended 
 CompletionCallback 
 ConnectionCallback 
Copyright 2014 Bhakti Mehta All rights reserved 
48
Asynchronous and long running jobs 
 Client side 
 InvocationCallback 
 Future 
Copyright 2014 Bhakti Mehta All rights reserved 
49
Asynchronous operations best practices 
 Send 202 Accepted if resource is not available 
immediately with Location 
 Use message queues to handle tasks asynchronously 
Copyright 2014 Bhakti Mehta All rights reserved 
50
Rate limiting 
 Rate limiting involves restricting the number of 
requests that can be made by a client. 
 A client can be identified based on the access token 
it uses for the request 
 Another way the client can be identified is the IP 
address of the client. 
Copyright 2014 Bhakti Mehta All rights reserved 
51
Rate limiting 
 The server can decide what the natural rate limit per 
client should be, say for example, 500 requests per 
hour. 
 The server checks if the request count is within the 
limit. 
 If the request count is within the limit, the request 
goes through and the count is increased for the 
client. 
 If the client request count exceeds the limit, the 
server can throw a 429 error. 
Copyright 2014 Bhakti Mehta All rights reserved 
52
Rate limiting and JAX-RS 
 Rate limiting can be implemented as a filter 
 This can check for the access count for a client and 
allow the messages to go through if within the limits 
 Else throw a 429 Error 
Copyright 2014 Bhakti Mehta All rights reserved 
53
Response pagination patterns 
 The following are the different techniques of 
pagination that can be used: 
 Offset-based pagination 
 Time-based pagination 
 Cursor-based pagination 
Copyright 2014 Bhakti Mehta All rights reserved 
54
Offset-based pagination 
 Offset-based pagination is the case when the client 
wants results specified by a page number and the 
number of results per page 
 GET v1/coffees/orders?page=1&limit=50 
Copyright 2014 Bhakti Mehta All rights reserved 
55
Time-based pagination 
 The time-based pagination technique will be used 
when the client wants to query for a set of results 
between a specific timeframe. 
 For example, GET 
v1/coffees/orders?since=140358321&until=1430874 
72 
Copyright 2014 Bhakti Mehta All rights reserved 
56
Cursor based pagination 
 The cursor-based pagination is a technique where 
the results are separated into pages by a cursor, and 
the results can be navigated forwards and backwards 
using the next and previous cursors that are 
provided in the response. 
Copyright 2014 Bhakti Mehta All rights reserved 
57
HATEOAS 
 Hypermedia as the Engine of Application 
State (HATEOAS) is a constraint of the REST 
application architecture. 
 Provides hypermedia links in the response sent by 
the server. 
Copyright 2014 Bhakti Mehta All rights reserved 
58
HATEOAS sample for book resource 
{ 
"Name":" Developing RESTful Services with JAX-RS 2.0, 
WebSockets, and JSON", 
"ISBN": "1782178120" 
"links": [ 
{ 
"rel": "self", 
"href": "http://packt.com/books/123456789" 
} 
] 
} 
Copyright 2014 Bhakti Mehta All rights reserved 
59
Authentication 
Copyright 2014 Bhakti Mehta All rights reserved 
60 
 Authentication enabled for all resources 
 Happens before any other validation 
 No access without validating the authentication 
token
Authorization 
Copyright 2014 Bhakti Mehta All rights reserved 
61 
 Authorization is the process of checking whether the 
requestor has permissions to perform the requested 
operation. 
 Happens after detecting a valid authentication 
 Happens before any validation
OAuth 
Copyright 2014 Bhakti Mehta All rights reserved 
62 
 User or resource owner: The user is the resource 
owner who wants to print his photos 
 Consumer application or client: This is the 
print service application, which will act on behalf of 
the user 
 Service provider or server: The service provider 
is the resource server that will store the user's photos
Oauth authorization grant flow 
Copyright 2014 Bhakti Mehta All rights reserved 
63
3 legged OAuth 
Copyright 2014 Bhakti Mehta All rights reserved 
64 
1. User wants to allow an application to do a task on his behalf. In our example, the 
task is to print photos, which are on a server using a consumer application. 
2. The consumer application redirects the user to the service provider's 
authorization URL. 
3. Here, the provider displays a web page asking the user if they can grant the 
application access to read and update their data. 
4. The user agrees to grant the application access by the print service consumer 
application. 
5. The service provider redirects the user back to the application (via the redirect 
URI), passing an authorization code as a parameter. 
6. The application exchanges the authorization code for an access grant. The service 
provider issues the access grant to the application. The grant includes an access 
token and a refresh token. 
7. Now that the connection is established, the consumer application can now obtain 
a reference to the service API and invoke the provider on behalf of the user. Thus, 
the print service can now access the user's photos from the service provider's site.
REST and micro services 
 Micro services vs Monolithic services 
 Advantages 
 Simplicity 
 Isolation of problems 
 Scale up and Scale down 
 Easy deployment 
 Clear Separation of concerns 
Copyright 2014 Bhakti Mehta All rights reserved 
65
REST and extensibility 
Copyright 2014 Bhakti Mehta All rights reserved 
66 
 Uniform interface constraint 
 Standard HTTP methods 
 Well defined representations of resources 
 Easy to use by myriad of clients from web, to mobile 
clients to other applications 
 Improves scalability, visibility and reliability
Emerging standards and future of REST 
 WebSockets 
 WebHooks 
 ServerSentEvents 
Copyright 2014 Bhakti Mehta All rights reserved 
67
WebSockets 
 Full duplex communication over TCP 
 Initial Handshake over HTTP for Upgrade request 
 Used for games, chat applications 
Copyright 2014 Bhakti Mehta All rights reserved 
68
WebSockets 
Copyright 2014 Bhakti Mehta All rights reserved 
69
WebHooks 
 User defined custom HTTP callbacks 
 Event producer sends event to the endpoint provided 
by client 
 Github WebHooks 
Copyright 2014 Bhakti Mehta All rights reserved 
70
WebHooks 
Copyright 2014 Bhakti Mehta All rights reserved 
71
Server-sent Events 
 Streaming model where clients get automatic 
updates from server 
 One direction communication from the server 
 QOS directives can be added to the message 
Copyright 2014 Bhakti Mehta All rights reserved 
72
Server-Sent Events 
Copyright 2014 Bhakti Mehta All rights reserved 
73
Comparisons 
Criteria WebHooks WebSockets SSE 
Long lived open 
Y Y 
connection 
Callback URK 
registered 
Y 
Bidirectional Y 
Needs Fallback to 
Y 
Polling 
Asynchronous real 
time 
communication 
Y Y Y 
Easy to implement Y Needs browser and 
proxy servers 
support 
Y 
Copyright 2014 Bhakti 
Mehta All rights reserved 
74
Questions 
 Blog 
https://www.java.net/blog/bhaktimehta 
 Twitter 
 @bhakti_mehta 
Copyright 2014 Bhakti Mehta All rights reserved 
75

More Related Content

What's hot

The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016Restlet
 
Implementing Advanced Caching and Replication Techniques in ...
Implementing Advanced Caching and Replication Techniques in ...Implementing Advanced Caching and Replication Techniques in ...
Implementing Advanced Caching and Replication Techniques in ...webhostingguy
 
Http2 protocol changes
Http2 protocol changesHttp2 protocol changes
Http2 protocol changesMark Friedman
 
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta jaxconf
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developersMario Cardinal
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developersPatrick Savalle
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServicesPrateek Tandon
 
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaCodemotion
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Introduction to the World Wide Web
Introduction to the World Wide WebIntroduction to the World Wide Web
Introduction to the World Wide WebAbdalla Mahmoud
 
Web Server Technologies II: Web Applications & Server Maintenance
Web Server Technologies II: Web Applications & Server MaintenanceWeb Server Technologies II: Web Applications & Server Maintenance
Web Server Technologies II: Web Applications & Server MaintenancePort80 Software
 
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
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Tech Brief Questions
Tech Brief Questions Tech Brief Questions
Tech Brief Questions webhostingguy
 

What's hot (20)

The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016
 
Implementing Advanced Caching and Replication Techniques in ...
Implementing Advanced Caching and Replication Techniques in ...Implementing Advanced Caching and Replication Techniques in ...
Implementing Advanced Caching and Replication Techniques in ...
 
Http2 protocol changes
Http2 protocol changesHttp2 protocol changes
Http2 protocol changes
 
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developers
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Introduction to the World Wide Web
Introduction to the World Wide WebIntroduction to the World Wide Web
Introduction to the World Wide Web
 
Servlet
ServletServlet
Servlet
 
Ftp servlet
Ftp servletFtp servlet
Ftp servlet
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
 
Web Server Technologies II: Web Applications & Server Maintenance
Web Server Technologies II: Web Applications & Server MaintenanceWeb Server Technologies II: Web Applications & Server Maintenance
Web Server Technologies II: Web Applications & Server Maintenance
 
Attacking REST API
Attacking REST APIAttacking REST API
Attacking REST API
 
Great webapis
Great webapisGreat webapis
Great webapis
 
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.
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Tech Brief Questions
Tech Brief Questions Tech Brief Questions
Tech Brief Questions
 

Viewers also liked

Architecting for Failures in micro services: patterns and lessons learned
Architecting for Failures in micro services: patterns and lessons learnedArchitecting for Failures in micro services: patterns and lessons learned
Architecting for Failures in micro services: patterns and lessons learnedBhakti Mehta
 
Fight empire-html5
Fight empire-html5Fight empire-html5
Fight empire-html5Bhakti Mehta
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiBhakti Mehta
 
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Expect the unexpected: Anticipate and prepare for failures in microservices b...Expect the unexpected: Anticipate and prepare for failures in microservices b...
Expect the unexpected: Anticipate and prepare for failures in microservices b...Bhakti Mehta
 
Resilience planning and how the empire strikes back
Resilience planning and how the empire strikes backResilience planning and how the empire strikes back
Resilience planning and how the empire strikes backBhakti Mehta
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTDavid Chandler
 
Expect the unexpected: Prepare for failures in microservices
Expect the unexpected: Prepare for failures in microservicesExpect the unexpected: Prepare for failures in microservices
Expect the unexpected: Prepare for failures in microservicesBhakti Mehta
 
Let if flow: Java 8 Streams puzzles and more
Let if flow: Java 8 Streams puzzles and moreLet if flow: Java 8 Streams puzzles and more
Let if flow: Java 8 Streams puzzles and moreBhakti Mehta
 

Viewers also liked (10)

Architecting for Failures in micro services: patterns and lessons learned
Architecting for Failures in micro services: patterns and lessons learnedArchitecting for Failures in micro services: patterns and lessons learned
Architecting for Failures in micro services: patterns and lessons learned
 
Devoxx2017
Devoxx2017Devoxx2017
Devoxx2017
 
50 tips50minutes
50 tips50minutes50 tips50minutes
50 tips50minutes
 
Fight empire-html5
Fight empire-html5Fight empire-html5
Fight empire-html5
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhakti
 
Expect the unexpected: Anticipate and prepare for failures in microservices b...
Expect the unexpected: Anticipate and prepare for failures in microservices b...Expect the unexpected: Anticipate and prepare for failures in microservices b...
Expect the unexpected: Anticipate and prepare for failures in microservices b...
 
Resilience planning and how the empire strikes back
Resilience planning and how the empire strikes backResilience planning and how the empire strikes back
Resilience planning and how the empire strikes back
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
Expect the unexpected: Prepare for failures in microservices
Expect the unexpected: Prepare for failures in microservicesExpect the unexpected: Prepare for failures in microservices
Expect the unexpected: Prepare for failures in microservices
 
Let if flow: Java 8 Streams puzzles and more
Let if flow: Java 8 Streams puzzles and moreLet if flow: Java 8 Streams puzzles and more
Let if flow: Java 8 Streams puzzles and more
 

Similar to Real world RESTful service development problems and solutions

Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web ServicesPaul Boocock
 
API_Design_Rest_Princple.pdf
API_Design_Rest_Princple.pdfAPI_Design_Rest_Princple.pdf
API_Design_Rest_Princple.pdfHuan Le Trong
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaVladimir Tsukur
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookKaty Slemon
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIsAparna Sharma
 
2022 APIsecure_Making webhook APIs secure for enterprise
2022 APIsecure_Making webhook APIs secure for enterprise2022 APIsecure_Making webhook APIs secure for enterprise
2022 APIsecure_Making webhook APIs secure for enterpriseAPIsecure_ Official
 
GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?LaunchAny
 
Modeling REST API's Behaviour with Text, Graphics or Both?
Modeling REST API's Behaviour with Text, Graphics or Both?Modeling REST API's Behaviour with Text, Graphics or Both?
Modeling REST API's Behaviour with Text, Graphics or Both?Ana Ivanchikj
 
Azure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalkAzure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalkShailesh Dwivedi
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...Jitendra Bafna
 
REST API Guidelines.pdf
REST API Guidelines.pdfREST API Guidelines.pdf
REST API Guidelines.pdfNickNack8
 
Will the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerWill the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerCodeValue
 

Similar to Real world RESTful service development problems and solutions (20)

Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Getting Started with API Management
Getting Started with API ManagementGetting Started with API Management
Getting Started with API Management
 
Api manager preconference
Api manager preconferenceApi manager preconference
Api manager preconference
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web Services
 
API_Design_Rest_Princple.pdf
API_Design_Rest_Princple.pdfAPI_Design_Rest_Princple.pdf
API_Design_Rest_Princple.pdf
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbook
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIs
 
2022 APIsecure_Making webhook APIs secure for enterprise
2022 APIsecure_Making webhook APIs secure for enterprise2022 APIsecure_Making webhook APIs secure for enterprise
2022 APIsecure_Making webhook APIs secure for enterprise
 
GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?GlueCon 2018: Are REST APIs Still Relevant Today?
GlueCon 2018: Are REST APIs Still Relevant Today?
 
Modeling REST API's Behaviour with Text, Graphics or Both?
Modeling REST API's Behaviour with Text, Graphics or Both?Modeling REST API's Behaviour with Text, Graphics or Both?
Modeling REST API's Behaviour with Text, Graphics or Both?
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Azure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalkAzure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalk
 
API Design- Best Practices
API Design-   Best PracticesAPI Design-   Best Practices
API Design- Best Practices
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 
REST API Guidelines.pdf
REST API Guidelines.pdfREST API Guidelines.pdf
REST API Guidelines.pdf
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
Will the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerWill the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir Zuker
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 

Real world RESTful service development problems and solutions

  • 1. Real world RESTful service development problems and solutions by Bhakti Mehta @bhakti_mehta
  • 2. Introduction  Senior Staff Engineer at Blue Jeans Network  Worked at Sun Microsystems/Oracle for 13 years  Committer to numerous open source projects including GlassFish Open Source Application Server Copyright 2014 Bhakti Mehta All rights reserved 2
  • 3. My latest book Copyright 2014 Bhakti Mehta All rights reserved 3
  • 4. Previous book Copyright 2014 Bhakti Mehta All rights reserved 4
  • 5. What you will learn  REST architectural style  Goals of REST  Design principles for REST  Advanced topics  Emerging standards and REST Copyright 2014 Bhakti Mehta All rights reserved 5
  • 6. What is REST?  All resources are identified by the URIs.  All resources can have multiple representations  All resources can be accessed/modified/created/deleted by standard HTTP methods.  There is no state information on the server. Copyright 2014 Bhakti Mehta All rights reserved 6
  • 7. Why REST?  Mature architectural style  Ease of use  Statelessness improves  Visibility  Reliability  Performance  Age of applications Copyright 2014 Bhakti Mehta All rights reserved 7
  • 8. Java API for RESTful Services  Standardized API as part of platform to build RESTful Services  Convert POJOs to RESTful Web Services using Annotations  Support for various representations  Improved support for client APIs Copyright 2014 Bhakti Mehta All rights reserved 8
  • 9. Design principles for building RESTful Services  Identify the resource URIs.  Identify the different representations supported by the resource  Implement the RESTful services using JAX-RS APIs  Deploy the RESTful services  Test the RESTful services Copyright 2014 Bhakti Mehta All rights reserved 9
  • 10. Resource URI patterns  Nouns representing a resource  Verbs representing an action on the resource  Safety  Idempotence Copyright 2014 Bhakti Mehta All rights reserved 10
  • 11. URI representation of a resource /v1/coffees To represent all the coffees that are sold by a coffee shop /v1/coffees/orders To represent all the coffees that are ordered /v1/coffees/orders/123 To represent a single coffee order of coffee identified by “123” /v1/users/5034/books To represent all the books for a user identified by “5034” Copyright 2014 Bhakti Mehta All rights reserved 11
  • 12. HTTP verbs and REST  GET  PUT  POST  DELETE  HEAD Copyright 2014 Bhakti Mehta All rights reserved 12
  • 13. HTTP verbs and actions GET v1/library/books Gets a list of books POST v1/library/books Creates a new book order DELETE v1/library/books/isbn/12345678 Deletes a book identified by ISBN “12345678” PUT v1/library/books/isbn/12345678 Updates a specific book identified by ISBN “12345678’ Copyright 2014 Bhakti Mehta All rights reserved 13
  • 14. Safety and Idepotence  Safe methods  Safe methods are methods that do not change the state on the server.  For example GET is a safe method.  Idempotent methods  This method produce the same results irrespective of how many times it is called.  For example GET, PUT and DELETE are idempotent Copyright 2014 Bhakti Mehta All rights reserved 14
  • 15. PUT vs POST  PUT vs POST  So POST /v1/coffees/orders means to create a new resource and return an identifier to describe the resource  In contrast PUT /v1/coffees/orders/1234 means to update a resource identified by “1234” if it exists else create a new order and use the URI orders/1234 to identify it.  PUT and POST can both be used to create or update methods. The usage of the method depends on the idempotence behavior expected from the method as well the location of the resource to identify it. Copyright 2014 Bhakti Mehta All rights reserved 15
  • 16. Best practices for RESTful resources  The API developer should use nouns to understand and navigate through resources  Use associations in the URIs to identify sub resources. For user/1234/books/5678/authors.  For specific variations use query parameters. For example to get all the books with 10 reviews /user/1234/books?reviews_counts=10 Copyright 2014 Bhakti Mehta All rights reserved 16
  • 17. Best practices for RESTful resources  Have defaults for the output format for the response  Have camelCase or use _ for attribute names.  Support a standard API for count for example users/1234/books/count  Support a pretty printing option users/1234?pretty_print. Copyright 2014 Bhakti Mehta All rights reserved 17
  • 18. Richardson Maturity Model Copyright 2014 Bhakti Mehta All rights reserved 18
  • 19. Richardson Maturity Model  Level 0 – Remote Procedure Invocation  SOAP or XML RPC and POX with POST  Level 1 – REST resources  POST with REST URIs  Level 2 – More HTTP Verbs  Verbs like GET, HEAD, PUT, DELETE  Level 3 – HATEOAS  Responses contain more details to help client take next action Copyright 2014 Bhakti Mehta All rights reserved 19
  • 20. REST architectural blocks Copyright 2014 Bhakti Mehta All rights reserved 20
  • 21. Content Negotiation  The process of selecting the best representation for a given response when there are multiple representations available.  Typical responses can be from  JSON  XML  TEXT  etc Copyright 2014 Bhakti Mehta All rights reserved 21
  • 22. Content Negotiation  Using HTTP headers  The Content-Type HTTP header is used to indicate the mime type of the entity being sent by the server  A client can make a request to the server and specify what media types it can handle and what is its order of preference as part of the “Accept” HTTP header. Copyright 2014 Bhakti Mehta All rights reserved 22
  • 23. Content Negotiation  Using URL patterns  Using resource representation based on extension of a resource in the URL.  For example a client can ask for details using http://foo.api.com/v2/library/books.xml orhttp://foo.api.com/v2/library/books.json Copyright 2014 Bhakti Mehta All rights reserved 23
  • 24. Content Negotiation and JAX-RS javax.ws.rs.Produces javax.ws.rs.Consumes @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addCoffee(Coffee coffee) { // Implementation here } Copyright 2014 Bhakti Mehta All rights reserved 24
  • 25. Versioning  For evolution of the application  It is hard to foresee all the resources, which will change over the life of the application.  The API developers must ensure that the HTTP verbs semantics and status codes should continue to work without human intervention as the version changes. Copyright 2014 Bhakti Mehta All rights reserved 25
  • 26. API versioning strategies  Specify the version in the URI itself.  Specify the version in the request query parameter  Specify the version in the Accept header Copyright 2014 Bhakti Mehta All rights reserved 26
  • 27. Version in the URI  For example http://api.foo.com/v2/coffees/1234  Additionally API developers can provide a path, which defaults to the latest version of the API. Thus the following request URI's should behave identically  http://api.foo.com/coffees/1234 http://api.foo.com/v2/coffees/1234 Copyright 2014 Bhakti Mehta All rights reserved 27
  • 28. Version in request query parameter  For example in the following URL v2 has been specified as part of the query parameter, ?version=v2  http://api.foo.com/coffees/1234?version=v2 Copyright 2014 Bhakti Mehta All rights reserved 28
  • 29. Version as part of mime type  Some APIs prefer to put version as part of the “Accept” header  For example Accept: application/vnd.foo-v1+json  In the above snippet vnd stands for vendor specific mime type.  GitHub uses this format Copyright 2014 Bhakti Mehta All rights reserved 29
  • 30. Case studies for versioning  Facebook, Twitter, Stripe API all use versions as part of the URI. Facebook API makes a version unusable two years after the date that the subsequent version is released. If a client makes a un-versioned call, the server will default to the oldest available version of the Facebook API.  Twitter API, provides a six months to completely transition from v1.0 from v1.1 Copyright 2014 Bhakti Mehta All rights reserved 30
  • 31. Specifying version in the Accept header  For example Accept: application/vnd.foo-v1+json  In the above snippet vnd stands for vendor specific mime type. This removes the version for the URL and is preferred by some API developers. Copyright 2014 Bhakti Mehta All rights reserved 31
  • 32. Error handling and Response codes  HTTP provides standardized response codes that can be returned for every request.  It is a good practice to not show a stack trace as part of the response  Use response codes to identify client or server side errors appropriately Copyright 2014 Bhakti Mehta All rights reserved 32
  • 33. REST response codes Group Response code Description Success 2XX 200 OK Used with PUT or POST or DELETE. It returns content as part of the response 201 Created used when creating a resource with PUT. It must contain the Location header of the resource. 204 No Content used for DELETE, POST or PUT operation. No content is returned as part of the response. Copyright 2014 Bhakti Mehta All rights reserved 33
  • 34. REST response codes Group Response code Description Success 2XX 202 Accepted Send response later as processing has not been completed as yet. Redirectional 3XX 301 Permanent All requests are directed to new location. 302 Found Resource is valid and exists Copyright 2014 Bhakti Mehta All rights reserved 34
  • 35. REST response codes Group Response code Description Client Error 4XX 401 Unauthorized Cannot process the request based on credentials 404 Not Found Resource is not found Server Errors 5xx 500 Internal Server Error Generic message when no specific exceptions are available Copyright 2014 Bhakti Mehta All rights reserved 35
  • 36. JAX-RS and Response codes JAX-RS defines a javax.ws.rs.core.Response class, which has static methods to create an instance using javax.ws.rs.core.Response.ResponseBuilder @POST Response addCoffee(...) { Coffee coffee = ... URI coffeeId = UriBuilder.fromResource(Coffee.class)... return Response.created(coffeeId).build(); } Copyright 2014 Bhakti Mehta All rights reserved 36
  • 37. Logging REST API  Complex distributed applications can introduce many points of failure  Logging is a very important aspect of building RESTful services especially in the case of debugging production issues in distributed nodes running various micro services.  It helps to link events or transactions between the various components that make an application or a business service. Copyright 2014 Bhakti Mehta All rights reserved 37
  • 38. Logging REST API best practices  Including a detailed consistent pattern across service logs  Obfuscating sensitive data  Identifying the caller or the initiator as part of the logs  Do not log payloads by default Copyright 2014 Bhakti Mehta All rights reserved 38
  • 39. Case studies of logging frameworks in distributed environments  Facebook has developed a homegrown solution called Scribe, which is a server for aggregating streaming log data.  Dapper is Google's tracing system, which samples data from the thousands of requests and provides sufficient information to trace data. Traces are collected in local log files and then pulled in Google's BigTable database. Copyright 2014 Bhakti Mehta All rights reserved 39
  • 40. Caching  Storing response information related to the requests in a temporary storage for a specific period of time.  Ensures that the server is not burdened with processing those requests in future when the responses can be fulfilled from the cache. Copyright 2014 Bhakti Mehta All rights reserved 40
  • 41. Caching Patterns  Types of Caching Headers  Strong Caching Headers  Weak Caching Headers Copyright 2014 Bhakti Mehta All rights reserved 41
  • 42. Strong Caching Headers  Cache-Control  Expires  The Expires and Cache-Control headers specify the time period during which the browser can use the cached resource without checking for a newer version.  Cache-Control max-age takes the time  Expires takes a date Copyright 2014 Bhakti Mehta All rights reserved 42
  • 43. Weak Caching Headers  ETag  Last-Modified  These headers enable the browser to check if the resource has changed since the last GET request. In the Last-Modified header, there is a date associated with the modification of the resource. In the ETag header, there can be any value that uniquely identifies a resource (like a hash). Copyright 2014 Bhakti Mehta All rights reserved 43
  • 44. JAX-RS and Caching headers @GET @Path("{order}") @Produces(MediaType.APPLICATION_XML) @NotNull(message = "Coffee does not exist for the order id requested") public Response getCoffee(@PathParam("order") int order) { Coffee coffee = CoffeeService.getCoffee(order); CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge(3600); cacheControl.setPrivate(true); Response.ResponseBuilder responseBuilder = Response.ok(coffee); responseBuilder.cacheControl(cacheControl); return responseBuilder.build(); } Copyright 2014 Bhakti Mehta All rights reserved 44
  • 45. Caching best practices  It is a good practice to specify either Expires or Cache-Control max-age along with one of the two Last-Modified and ETag headers in the HTTP response. Sending both Expires and Cache-Control max-age is redundant. Similarly, sending both Last- Modified and ETag is redundant Copyright 2014 Bhakti Mehta All rights reserved 45
  • 46. Caching best practices  Cache on GET request  Invalidate cache on PUT, POST or DELETE  Periodically purge cache entries Copyright 2014 Bhakti Mehta All rights reserved 46
  • 47. Asynchronous and long running jobs in REST  A common pattern in developing RESTful API is to deal with asynchronous and long running jobs.  API developers need to create resources that might take a considerable amount of time  They cannot have the clients wait on the API to finish. Copyright 2014 Bhakti Mehta All rights reserved 47
  • 48. Asynchronous and long running jobs  Server side:  AsyncResponse  @Suspended  CompletionCallback  ConnectionCallback Copyright 2014 Bhakti Mehta All rights reserved 48
  • 49. Asynchronous and long running jobs  Client side  InvocationCallback  Future Copyright 2014 Bhakti Mehta All rights reserved 49
  • 50. Asynchronous operations best practices  Send 202 Accepted if resource is not available immediately with Location  Use message queues to handle tasks asynchronously Copyright 2014 Bhakti Mehta All rights reserved 50
  • 51. Rate limiting  Rate limiting involves restricting the number of requests that can be made by a client.  A client can be identified based on the access token it uses for the request  Another way the client can be identified is the IP address of the client. Copyright 2014 Bhakti Mehta All rights reserved 51
  • 52. Rate limiting  The server can decide what the natural rate limit per client should be, say for example, 500 requests per hour.  The server checks if the request count is within the limit.  If the request count is within the limit, the request goes through and the count is increased for the client.  If the client request count exceeds the limit, the server can throw a 429 error. Copyright 2014 Bhakti Mehta All rights reserved 52
  • 53. Rate limiting and JAX-RS  Rate limiting can be implemented as a filter  This can check for the access count for a client and allow the messages to go through if within the limits  Else throw a 429 Error Copyright 2014 Bhakti Mehta All rights reserved 53
  • 54. Response pagination patterns  The following are the different techniques of pagination that can be used:  Offset-based pagination  Time-based pagination  Cursor-based pagination Copyright 2014 Bhakti Mehta All rights reserved 54
  • 55. Offset-based pagination  Offset-based pagination is the case when the client wants results specified by a page number and the number of results per page  GET v1/coffees/orders?page=1&limit=50 Copyright 2014 Bhakti Mehta All rights reserved 55
  • 56. Time-based pagination  The time-based pagination technique will be used when the client wants to query for a set of results between a specific timeframe.  For example, GET v1/coffees/orders?since=140358321&until=1430874 72 Copyright 2014 Bhakti Mehta All rights reserved 56
  • 57. Cursor based pagination  The cursor-based pagination is a technique where the results are separated into pages by a cursor, and the results can be navigated forwards and backwards using the next and previous cursors that are provided in the response. Copyright 2014 Bhakti Mehta All rights reserved 57
  • 58. HATEOAS  Hypermedia as the Engine of Application State (HATEOAS) is a constraint of the REST application architecture.  Provides hypermedia links in the response sent by the server. Copyright 2014 Bhakti Mehta All rights reserved 58
  • 59. HATEOAS sample for book resource { "Name":" Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON", "ISBN": "1782178120" "links": [ { "rel": "self", "href": "http://packt.com/books/123456789" } ] } Copyright 2014 Bhakti Mehta All rights reserved 59
  • 60. Authentication Copyright 2014 Bhakti Mehta All rights reserved 60  Authentication enabled for all resources  Happens before any other validation  No access without validating the authentication token
  • 61. Authorization Copyright 2014 Bhakti Mehta All rights reserved 61  Authorization is the process of checking whether the requestor has permissions to perform the requested operation.  Happens after detecting a valid authentication  Happens before any validation
  • 62. OAuth Copyright 2014 Bhakti Mehta All rights reserved 62  User or resource owner: The user is the resource owner who wants to print his photos  Consumer application or client: This is the print service application, which will act on behalf of the user  Service provider or server: The service provider is the resource server that will store the user's photos
  • 63. Oauth authorization grant flow Copyright 2014 Bhakti Mehta All rights reserved 63
  • 64. 3 legged OAuth Copyright 2014 Bhakti Mehta All rights reserved 64 1. User wants to allow an application to do a task on his behalf. In our example, the task is to print photos, which are on a server using a consumer application. 2. The consumer application redirects the user to the service provider's authorization URL. 3. Here, the provider displays a web page asking the user if they can grant the application access to read and update their data. 4. The user agrees to grant the application access by the print service consumer application. 5. The service provider redirects the user back to the application (via the redirect URI), passing an authorization code as a parameter. 6. The application exchanges the authorization code for an access grant. The service provider issues the access grant to the application. The grant includes an access token and a refresh token. 7. Now that the connection is established, the consumer application can now obtain a reference to the service API and invoke the provider on behalf of the user. Thus, the print service can now access the user's photos from the service provider's site.
  • 65. REST and micro services  Micro services vs Monolithic services  Advantages  Simplicity  Isolation of problems  Scale up and Scale down  Easy deployment  Clear Separation of concerns Copyright 2014 Bhakti Mehta All rights reserved 65
  • 66. REST and extensibility Copyright 2014 Bhakti Mehta All rights reserved 66  Uniform interface constraint  Standard HTTP methods  Well defined representations of resources  Easy to use by myriad of clients from web, to mobile clients to other applications  Improves scalability, visibility and reliability
  • 67. Emerging standards and future of REST  WebSockets  WebHooks  ServerSentEvents Copyright 2014 Bhakti Mehta All rights reserved 67
  • 68. WebSockets  Full duplex communication over TCP  Initial Handshake over HTTP for Upgrade request  Used for games, chat applications Copyright 2014 Bhakti Mehta All rights reserved 68
  • 69. WebSockets Copyright 2014 Bhakti Mehta All rights reserved 69
  • 70. WebHooks  User defined custom HTTP callbacks  Event producer sends event to the endpoint provided by client  Github WebHooks Copyright 2014 Bhakti Mehta All rights reserved 70
  • 71. WebHooks Copyright 2014 Bhakti Mehta All rights reserved 71
  • 72. Server-sent Events  Streaming model where clients get automatic updates from server  One direction communication from the server  QOS directives can be added to the message Copyright 2014 Bhakti Mehta All rights reserved 72
  • 73. Server-Sent Events Copyright 2014 Bhakti Mehta All rights reserved 73
  • 74. Comparisons Criteria WebHooks WebSockets SSE Long lived open Y Y connection Callback URK registered Y Bidirectional Y Needs Fallback to Y Polling Asynchronous real time communication Y Y Y Easy to implement Y Needs browser and proxy servers support Y Copyright 2014 Bhakti Mehta All rights reserved 74
  • 75. Questions  Blog https://www.java.net/blog/bhaktimehta  Twitter  @bhakti_mehta Copyright 2014 Bhakti Mehta All rights reserved 75

Editor's Notes

  1. This is an injectable JAX-RS asynchronous response that provides means for asynchronous server-side response processing AsyncResponse: This is an injectable JAX-RS asynchronous response that provides means for asynchronous server-side response processing @Suspended: The @Suspended  annotation  instructs the container that the HTTP request processing should happen in a secondary thread CompletionCallback: This is a request processing callback that receives request processing completion events ConnectionCallback: This is an asynchronous request processing life cycle callback that receives connection-related asynchronous response life cycle events
  2. InvocationCallback: This is a callback that can be implemented to receive the asynchronous processing events from the invocation processing Future: This allows the client to poll for completion of the asynchronous operation or to block and wait for it