real-world restful service development problems and solutions

59

Upload: masoud-kalali

Post on 14-Nov-2014

178 views

Category:

Software


0 download

DESCRIPTION

This session covers some of the best practices and lessons learned and takes a deep dive into designing RESTful services. It discusses a variety of topics, from validation and exception handling to tracing, caching, security, rate limiting, and other RESTful services topics. The presentation is suitable for anyone from novices to advanced programmers.

TRANSCRIPT

Page 1: Real-World RESTful Service Development Problems and Solutions
Page 2: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Real-­‐World  RESTful  Service  Development  Problems  and  SoluKons  

Masoud  Kalali,  SoNware  Engineer  at  ORACLE,  @MasoudKalali  

Page 3: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Safe  Harbor  Statement  The  following  is  intended  to  outline  our  general  product  direcKon.  It  is  intended  for  informaKon  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  funcKonality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  Kming  of  any  features  or  funcKonality  described  for  Oracle’s  products  remains  at  the  sole  discreKon  of  Oracle.  

Page 4: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Program  Agenda  

IntroducKon  

Basics  of  RESTful  services  and  Java  

What  to  consider  when  designing  resources  

A  liWle  bit  of  security  

Performance  maWers!  

More  common  paWerns  

Emerging  standards    

1  

2  

3  

4  

5  

6  

7  

Page 5: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Speaker  

•  Masoud  Kalali  •  SoNware  engineer,  author,  blogger…  •  Listens  to  high  definiKon  Audio  (you  got  what  I  mean)  •  @MasoudKalali  

Page 6: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

IntroducKon  

Basics  1.  REST  basic  best  pracKces  2.  Java  and  REST  

Problems  and  Pa;erns  1.  Common  problems  and  soluKons  2.  A  liWle  dive  into  emerging  standards      

Page 7: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Basics  of  RESTful  services  and  Java  REST  Basics    Java  Standard  API  for  REST  Resource  Design  Response  Desing      

Page 8: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

REST  Basics    

•  The  idea  • Unified  predictable  interface  • Maturity  of  the  underlying  protocols  •  The  ease  of  use  • Vast  and  expanding  adopKon  • Age  of  Apps  

What  is  REST?  

Page 9: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Resource  Design  paWerns  

• Resources  – names  – path  formaKon  

• Verbs  – Idempotency  – Safety,  Cache-­‐ability  

How  to  design  the  resources?   GET  hWp://cdom.com/api/v1/customers/1  GET  hWp://cdom.com/api/v1/customers/1/orders/1    Not  Good:  GET  hWp://cdom.com/api/v1/customers/1?delete=true  POST  hWp://cdom.com/api/v1/customers/1?delete=true    

Page 10: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

HTTP  verbs:  Idempotency  and  safety  

Verb   Ideompotency   Safety   Cached   Data/URI  length  limit  

GET   ✔   ✔   ✔   2048  Characters  

PUT   ✔   ✗   ✗   No  Limit  

POST   ✗   ✗   ✗   No  Limit  

DELETE   ✔   ✗   ✗   Depends*  

PATCH**   ✗   ✗   ✗   No  Limit  

How  to  design  the  resources?  

•  *  Some  older  HTTP  servers,  proxies  may  reject  a  DELETE  request  which  carry  payload.  •  **  Not  supported  by  all  hops    

Page 11: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Request/Response  paWerns  

• Response  status  codes  – There  are  more  than  200,  404  and  500!  

• Unified  response  style  – Predictability  of  response  body  – ApplicaKon  specific  error  code  – Human  readable  message  – cause/soluKon  

How  should  a  resource  respond  to  a  request?  

Page 12: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Java  Standard  API  for  REST  

•  Long  available  HTTP  client  libraries  •  Long  available  Servlets  • Recent  adopKon  of  POJO  to  resources  mapping,  JAX-­‐RS…  • Recent  standardizaKon  of  resource  clients  • BeWer  integraKon  and  use  of  JSON  •  Incredible  number  of  libraries  and  frameworks  

What  Java  has  to  say  here?  

Page 13: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Basics  of  RESTful  services  and  Java  Code  and  Demo  Tme!      

Page 14: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Request  and  Response….  Content  NegoTaTon  Resource  Versioning  ValidaTon  ExcepTon  Handling  

Page 15: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Content  NegoKaKon  

• Produce  mulKple  types  of  response  – JSON  – XML  – HTML  

• Produce  mulKple  semanKcally  different  response  – Based  on  user  agent  – Based  on  custom/domain  oriented  media  types  – Base  on  both  

Flexible  response  types  

Page 16: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Content  NegoKaKon  

• On  the  server  side  – @Produce  •  Should  have  matching  media-­‐type  with  request  accept  header  •  Non  matching  results  in  406  -­‐  Not  Acceptable  

– @Consume  •  Should  have  matching  media-­‐type  with  request  content-­‐type  header  •  Non  matching  results  in  415  -­‐  Unsupported  Media  Type  

• On  the  client  side  – Set  correct  content-­‐type  – Set  expected  accept  header  

JAX-­‐RS  and  flexible  response  types  

Page 17: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Resource  Versioning  

•  Request  and  or  response  evolves  to  be  incompaKble  •  Business  semanKc  evolves  to  become  incompaKble  •  Version  added  to  resource  (URI)  – Client  is  locked  to  the  version  •  Problems  like  linked  resource  address  stored  in  client  side…    

•  Version  is  negoKated  as  part  of  the  request  – Serve  code  need  to  handle  all  supported  previous  versions  

•  No  version,  the  big  bang  migraKon  – Too  costly  for  clients  – Too  hard  to  coordinate  

How  to  evolve  a  resource?  

Page 18: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ValidaKon  

• ValidaKon  goes  with  versioning  and  content  negoKaKon  • Unified  validaKon  paWerns  across  the  codebase  – Codified  response  format  – Unified  response  body  

• Use  annotaKons  and  standard  validaKon  as  much  as  possible  – Supports  common  media-­‐types  – Unified  with  custom  coding/template  being  added  

ValidaTon  before  acTon!  

Page 19: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ExcepKon  Handling  

• Please  don’t  send  back  stack  trace  – Use  an  ExcepKonMapper  as  Provider  as  last  line  of  cleanup!  – Unless  in  development  environment  (with  some  consideraKons)  

• Codify  all  failures  and  include  cause/acKon  in  the  response  – Use  right  hWp  status  code  – Add  applicaKon  level  code  for  codifying  issues  – Add  human  understandable  message  

 

There  are  always  unforeseen  corner  cases!  

Page 20: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

What  to  consider  when  designing  resources  Code  and  Demo  Tme!  

Page 21: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

A  liWle  bit  of  security  AuthenTcaTon  Access  control  AudiTng      

Page 22: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

AuthenKcaKon  

• AuthenKcaKon  enabled  for  all  resources  • Happens  before  any  other  validaKon  •  Exclude  the  resource  paWerns  that  requires  no  authenKcaKon  • No  access  without  validaKng  the  authenKcaKon  token  

Know  who  is  requesTng  a  resource  

Page 23: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Access  control  

• Happens  aNer  detecKng  a  valid  authenKcaKon  • Requests  are  easy  to  check  – Unless  column  level  checks  are  required,  can  be  done  in  simple  filter  – Column  level  access  control  can  be  done  using  media  types  

• Happens  before  any  validaKon  – unless  params  are  being  used  as  part  of  the  access  check  

Check  who  can  access  a  resource  

Page 24: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

AudiKng/  Access  logs  

• Keep  a  rich  access  log  – Depending  on  the  server  you  use  

•  Include  the  usual  who,  when,  what    •  Try  using  W3C  Extended  Log  File  Format  if  supported  by  server  • Configure  security  realm  for  logging  •  Think  ahead  about  incident  detecKon/isolaKon,  etc.  

Keep  record  of  security  incidents!  

Page 25: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

A  liWle  bit  of  Security  Code  and  Demo  

Page 26: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Performance  maWers!  Caching  ParTal  Updates  &  HTTP  PATCH  Asynchronous  And  long  running  jobs  in  REST      

Page 27: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Caching  

•  Local  Cache  • Proxy  Cache  •  reverse-­‐proxy  (cache)  •  Server(ApplicaTon)  Level  Cache  

Being  sTngy  with  the  resource  usage  is  OK!  

Page 28: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Caching  

• Use  HTTP  caching  features  • Client  aware  of  provided  caching  support  •  Server  evaluate  caching  related  headers  •  intermediately  hops    •  Types  of  Caching  Headers  – Absolute  Caching  Headers  – CondiKonal  Caching  Headers  

ApplicaTon  Level  Cache  

Page 29: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Caching  

•  From  Server  side:  – Cache-­‐Control  and  direcKves  – Last-­‐Modified  

Absolute  Caching  

HTTP/1.1  200  OK  Content-­‐Type:  applicaKon/json  Cache-­‐Control:  private,  max-­‐age=86400  Last-­‐Modified:  Thur,  01  Apr  2014  11:30  PST  

• private  • public  • no-­‐cache  • no-­‐store  • max-­‐age  (overrides  Expires)  

Cache  Control  DirecTves  

Page 30: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Caching  

•  From  client  side  send  headers:  – If-­‐None-­‐Match  =  "If-­‐None-­‐Match"  ":"  (  "*"  |  1#enKty-­‐tag  )  – If-­‐Modified-­‐Since  =  "If-­‐Modified-­‐Since"  ":"  HTTP-­‐date  

• At  the  server  side  produce  headers:  – Etag,  when  last-­‐modified  is  hard  to  determine  

CondiTonal  Caching  

HTTP/1.1  200  OK  Content-­‐Type:  applicaKon/json  Etag:  "8b329b598fcdad4fd33432e78128da48f72198829640882”  

Page 31: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

@GET  @Consumes({JSON_TYPE})  @Produces({JSON_TYPE,  MediaType.APPLICATION_JSON,  MediaType.TEXT_PLAIN})  @Path("simple")  public  Response  myGeWer(@PathParam("simple")  int  id,  @Context  Request  request)  {          Simple  simple  =  new  Simple(id,"John",  "Due",  new  Date());          if  (request.evaluatePrecondiKons(simple.getLastModified())  ==  null)  {                  CacheControl  cacheControl  =  new  CacheControl();                  cacheControl.setMaxAge(3600);                  cacheControl.setPrivate(true);                  Response.ResponseBuilder  responseBuilder  =                                  Response.ok(simple);                  responseBuilder.cacheControl(cacheControl).lastModified(simple.getLastModified());                  EnKtyTag  enKtyTag  =  new  EnKtyTag(getEtagFor(simple),  false);                  return  responseBuilder.tag(enKtyTag).build();          }          return  Response.notModified().build();  }  

curl  -­‐v  -­‐X  GET  -­‐H  "Content-­‐Type:applicaKon/json"  -­‐H  "Accept:applicaKon/json"  -­‐H  "If-­‐Modified-­‐Since:Mon,  08  Sep  2014  15:08:27  GMT"  hWp://.../simple/1  

Page 32: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Caching  

• Can  be  used  for  conflict  resoluKon  • Cache  on  GET  request  •  Invalidate  cache  on  PUT,  POST  or  DELETE  • Periodically  purge  cache  entries  • Cache  invalidaKon,  evicKon  is  not  determinisKc  • Give  hWp://www.jboss.org/resteasy  a  try  – Provides  @Cache  and  @NoCache  – Extension  to  JAX-­‐RS  

More  on  Caching  

Page 33: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ParKal  Updates  &  HTTP  PATCH  

• ParKal  Updates  with  PUT  • ParKal  Updates  with  POST  • ParKal  updates  with  PATCH  •  JSON  Patch  is  the  future  

Only  update  what  needs  to  be  updated!  

Page 34: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ParKal  Updates  &  HTTP  PATCH  

• ParKally  update  a  JSON  document  • Works  with  HTTP  PATCH  • Requires  special  body  syntax  and  direcKves  

JavaScript  Object  NotaTon  (JSON)  Patch,  RFC  6902  

PATCH  /coffee/orders/1234  HTTP/1.1  Host:  api.foo.com  Content-­‐Length:  100  Content-­‐Type:  applicaKon/json-­‐patch  [  {“op”:"replace",  ”path”:  "/status",  "value":  "COMPLETED"}  ]  

Page 35: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ParKal  Updates  &  HTTP  PATCH  

•  Supports  six  operaKons  in  the  payload  – op  :  can  be    “add”,  “replace”,  “move”,  “remove”,  “copy”  or  “test”  

• Another  three  aWributes  to  describe  the  op  – path:  LocaKon  of  the  target  aWribute  in  the  JSON  document  – value:  The  new  value  to  be  added  or  to  replace  another  – from:  (Only  for  move  op)  specifies  the  source  locaKon    

JavaScript  Object  NotaTon  (JSON)  Patch,  RFC  6902  

Page 36: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Asynchronous  And  long  running  jobs  in  REST    

• On  the  serverside:  – @Asynchronous:  Annotate  a  sub-­‐resource  as  Asynchronous  – AsyncResponse:  Provides  results  an  acKons  on  the  running  request  •  se�ng  Kmeout  •  registering  callbacks  •  resume,  cancel  suspended  request  processing  •  updaKng  the  response    

– @Suspended:  To  inject  a  suspended  AsyncResponse  into  a  sub-­‐resource  parameter  

Don’t  keep  unnecessary  resources  for  where  not  needed!  

Page 37: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Asynchronous  And  long  running  jobs  in  REST    

• On  the  serverside:  – CompleKonCallback:  Async  response  processing  compleKon  callback  •  Response  processing  completed  and  sent  to  client  •  Response  processing  failed  with  excepKon  

– ConnecKonCallback:  Client  server  connecKon  events  callback  •  Client  is  disconnected  abruptly  (before  or  during  wriKng  back  the  response)  

Server  side  callbacks  

Page 38: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Asynchronous  And  long  running  jobs  in  REST    

@GET  @Produce(“applicaKon/json”)  

@Asynchronous  

public  void  getOrder(@Suspended  AsyncResponse  ar,  String  orderId)  {  

 final  String  result  =  prepareResponse(orderId);  

 ar.resume(result)  

}  

Some  small  sample  code  

Future<Coffee>  future  =  client.target(“/coffees/orderId")  .request()  .async()  .get(Coffee.class);  try  {  

 Coffee  coffee  =  future.get(30,  TimeUnit.SECONDS);  }  catch  (TimeoutExcepKon  ex)  {  

 //  }  

Client  Code:  

Server  Code:  

**  AlternaKve  to  Future  is  using  InvocaKonCallback  to  get  called  when  response  is  back  

Page 39: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Asynchronous  And  long  running  jobs  in  REST    

•  Send  202  where  response  is  not  ready  with  LocaKon  header  – Intelligent  enough  client  can  query  the  resource  locaKon  with  the  given  Retry-­‐Aier  header  – Beware  of  transacKonal  mulK  step  long  running  tasks  

• Use  message  queues  to  process  tasks  in  background  

Don’t  keep  unnecessary  resources  for  where  not  needed!  

Page 40: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Performance  maWers!  Code  and  Demo  

Page 41: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Few  more  topics  Response  PaginaTng  Usage  Thro;ling  REST  and  plug-­‐ability  and  extensibility    

Page 42: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Response  PaginaKng  

• Offset  based  paginaKon  – Page  and  limit  

• Cursor  based  paginaKon  – A  pointer  to  the  next  and  previous  set  – Possible  use  of  HATEOAS  

•  Time  based  paginaKon  – Since  and  to  for  indicaKng  a  Kme  based  query  

Paginate  the  record  sets  when  possible  

Page 43: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Response  PaginaKng  PaWerns  

•  Include  defaults  incase  client  does  not  specify  page  number  and  number  of  results  per  page  •  Include  meta  data  in  response  so  client  knows  what  is  the  next  set  of  results  to  navigate  to  

Paginate  the  record  sets  when  possible  

Page 44: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ThroWling  PaWerns  

• Why  use  Rate  LimiKng?  – Prevent  and  handle  abuse  – Provide  beWer  support  for  premium  users  

• How  Rate  LimiKng  works?  – Servlet  filter  sits  in  front  – User  user  tokens  or  IP  addresses  as  idenKfiers  – Use  in-­‐memory  cache  for  book  keeping  – Prevents  requests  reaching  endpoints  when  limit  reached  – Reset  update  cached  counters  when  needed  

Keep  tap  on  how  many  request  one  user  can  send!  

Page 45: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ThroWling  PaWerns  

• Response  status,  headers  – HTTP  429  Too  Many  Requests  error  code  – Retry-­‐ANer  header  – X-­‐RateLimit-­‐Limit:  ###  – X-­‐RateLimit-­‐Remaining:  ###  – X-­‐RateLimit-­‐Reset:  EPOCH_SECONDS  

• DescripKve  response  in  the  requested  media  type  

Headers  and  response  

Page 46: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ThroWling  PaWerns  

• Client  side  – Use  caching  – keep  tap  on  number  of  requests  – Pay  aWenKon  to  headers  – No  brainless  loops  (polling)  

•  Server  side  – Support  caching  (etags  and  max-­‐age)  – provide  streaming  endpoints  when  possible  (feeds,  news,  public  data)  

Best  pracTces  

Page 47: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

REST  and  plug-­‐ability  and  extensibility  

• Micro  services  vs  Monolithic  services  • Advantages  – Simplicity  – IsolaKon  of  problems  – Scale  up  and  Scale  down  – Easy  deployment  – Clear  SeparaKon  of  concerns  

Micro  services  design  pa;ern!  

Page 48: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

REST  extensibility  

• Uniform  interface  constraint  •  Standard  HTTP  methods  • Well  defined  representaKons  of  resources  •  Easy  to  use  by  myriad  of  clients  from  web,  to  mobile  clients  to  other  applicaKons  •  Improves  scalability,  visibility  and  reliability  

How  is  REST  extensbile?  

Page 49: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

A  liWle  of  advanced  topics  Code  and  Demo  

Page 50: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Emerging  standards    WebSockets,  Web  hooks,  etc.  The  role  of  REST  in  a  future  evolving  web  standards      

Page 51: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

WebSockets,  Web  Hooks,  etc.  

• WebSockets  • WebHooks  •  ServerSentEvents  

RESTful  services  brethren!  

Page 52: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

WebSockets  

•  Full  duplex  communicaKon  over  TCP  •  IniKal  Handshake  over  HTTP  for  Upgrade  request  • Use  when  full  duplex  communicaKon  is  required  

RESTful  services  brethren!  

Page 53: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

WebHooks  

• User  defined  custom  HTTP  callbacks  •  Event  producer  sends  event  to  the  endpoint  provided  by  client  • Github  WebHooks  

RESTful  services  brethren!  

Page 54: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

ServerSentEvents  

•  Streaming  model  where  clients  get  automaKc  updates  from  server  • One  direcKon  communicaKon  from  the  server  • QOS  direcKves  can  be  added  to  the  message  

RESTful  services  brethren!  

Page 55: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Comparisons  

Criteria   WebHooks   WebSockets   SSE  

Long  lived  open  connecKon   Y   Y  

Callback  URI  registered   Y  

BidirecKonal   Y  

Needs  Fallback  to  Polling   Y  

Asynchronous  real  Kme  communicaKon  

Y   Y   Y  

Easy  to  implement   Y   Needs  browser  and  proxy  servers  support  

Y  

RESTful  services  brethren!  

Page 56: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Emerging  standards    Code  and  Demo  

Page 57: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Comments,  QuesKons?  

Page 58: Real-World RESTful Service Development Problems and Solutions

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

•  RESTful  Services  Patterns  and  best  practices  By  Bhakti  Mehta,  http://www.amazon.com/RESTful-­‐Java-­‐Patterns-­‐Best-­‐Practices/dp/1783287969/  

•  http://tools.ietf.org/html/rfc6902  •  http://tools.ietf.org/html/rfc6901  •  http://resteasy.jboss.org/  •  https://jersey.java.net/documentation/latest/  •  http://tools.ietf.org/html/rfc6585  •  http://tools.ietf.org/html/rfc5789  •  CCL  photos  used  in  slides:  

•  https://www.flickr.com/photos/treehouse1977/2892417805/  •  https://www.flickr.com/photos/treehouse1977/2892417805/  •  https://www.flickr.com/photos/essjay/165928100/  •  https://www.flickr.com/photos/jforth/4413370462/  •  https://www.flickr.com/photos/sakalak/8737872379/  •  https://www.flickr.com/photos/jbparrott/8980026600  •  https://www.flickr.com/photos/pentadact/36593493/  •  https://www.flickr.com/photos/jasohill/4442279347/  •  https://www.flickr.com/photos/mdsharpe/5075953655  •  https://www.flickr.com/photos/chuqvr/8329512894/  •  https://www.flickr.com/photos/longo/2684733921  •  https://www.flickr.com/photos/_davor/14757399908  

Resources  

Page 59: Real-World RESTful Service Development Problems and Solutions