REST  APIs REpresentational  State  Transfer  of  an Application  Programming  Interface
Who  Am  I? @Francainath
This  is  what  I  do:  (+   )     (REST)
In  the  Beginning...
Changing  landscape
Where  we  are  today:
PROBLEM: How  can  we  make  our  app  work  on  all these  devices?
solution  #1:  RESPONSIVE  DESIGN  
solution  #2:  CUSTOM  APPS   Unique  app  for  each  environment    
Are  we  gonna  write  a  new  app  for EVERY  DEVICE?
0:01
ColdBox  REST
REST  APIs REpresentational  StateTransfer  of  an Application  Programming  Interface We  are  going  to  transform  our ColdBox  program  into  an  API  and access  it  through  a  RESTful  interface
STEP  #1:  API Start  w/a    app
STEP  #1:  API Make  it  headless  &  start  api  module
STEP  #2:  REST URI  routes  are  built  up  w/a  combo  of resources  and  actions Resources  =  objects made/managed  thru  the  model represented  by  nouns Actions  =  functions built  in  the  handlers represented  by  verbs
Basic  Handler
Routes Routes  =  "how  we  reach  our  handlers" built  in  the  ModuleConfig.cfc Build  them  up  with: resource  (nouns) action  (verbs)
basic  ModuleConfig.cfc
Example  routes List  players? (baseURL)/api/player/list Get  a  player?  (http  verb  GET) (baseURL)/api/player/:playerID Make  a  player?  (http  verb  POST) (baseURL)/api/player/:playerID
-­    docs Returning  data "The  most  common  way  to  return  data from  your  handler's  action  is  to  use the  even  object's  renderData() method.  It  takes  complex  data  and turns  it  into  a  string  representation"
Return  data  formats XML JSON TEXT WDDX PDF HTML
Setting  up  a  return
Well,  that  was   Wasn't  it?
Well,  it  was... Bare  Bones!
0:03
Beyond  "bare  bones" Status  Codes Caching Security Restricting  HTTP  Verbs Error  Handling Relax
Status  Codes 200  "OK" 202  "Created" 400  "Bad  Request" 401  "Unauthorized" 404  "Not  Found" 500  "Server  Error"
Using  Status  Codes 1.  event.renderData()  (shortcut) statusCode  &  statusMessage  attr 2.  event.setHTTPHeader()  (manual) statusCode  &  statusText  attr
Restricting  HTTP  verbs in  our  routes,  we  mapped  HTTP  verbs to  handler  actions,  but  how  can  we prevent  users  from  hitting  resources w/the  wrong  verbs?  (aka  a  GET  to  a delete  function)
this.allowedMethods allowedMethods  property  in  handler can  restrict  those  connections  for  us
RELAX!!! and  now...
Resources Coldbox  REST  docs http://wiki.coldbox.org/wiki/Building_Rest_APIs.cfm Coldbox  REST  Refcard  (PDF) https://github.com/ColdBox/cbox-­ refcards/raw/master/ColdBox%20REST%20APIs/Cold REST-­APIs-­Refcard.pdf Coldbox  Relax  docs http://wiki.coldbox.org/wiki/Projects:Relax.cfm

CBDW2014 - ColdBox RESTFul Services