how we rest
DESCRIPTION
Nathaniel Francis How we RESTTRANSCRIPT
How We Rest
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 allthese devices?
solution #1: RESPONSIVE DESIGN
solution #2: CUSTOM APPS Unique app for each environment
This requires:
Why REST?When compared to SOAP(Simple Object Access Protocol),REST is considered:
lighter weighteasier to use (for the most part)more flexible
REST basicsApp architecture styleHTTP request-response model
hence web focused
REpresentational State TransferSupports HTTP methods:
GET, POST, PUT, DELETE, OPTIONS
Returns data in different formatsJSON, text, XML, etc.
How We Rest5 key options
2 servers
3 frameworks
Natively available in CF10+Uses separate servlet to run RESTRegister your RESTful servicesregister/manage RESTful aspects inCFC via metadata
Setup/Configuration
RestInitApplication(rootPath[,serviceMapping[,options]])
(in application.cfc)
Routing{domain}/rest/{serviceMapping}/{subResource}
Example:{domain}/rest/fantasyFootball/getQuarterback/{id}
CFC code
SHOW TIME!!!(examples/CF10quarterback.cfcin github repo)
Considerations"/rest" mapping
can change this by revising the context path for the RESTservlet in web.xml
Metadata in CFCsAdvocates: truly RESTCritics: verbose, confusing
Natively available in Railo 4+Uses separate servlet to run RESTRegister your RESTful servicesregister/manage RESTful aspects inCFC via metadata
Setup/Configuration
RestInitApplication(rootPath[,serviceMapping[,options]])
(in application.cfc)
Routing{domain}/rest/{service}/{action}{domain}/rest/fantasyFootball/getRunningback/{id}
CFC code
SHOW TIME!!!(examples/RailoRunningBack.cfcin github repo)
Considerations"/rest" mapping
{domain}/rest/{service}/{action}
Metadata in CFCsAdvocates: truly RESTCritics: verbose, confusing
REST focused frameworkDesign: make REST simple for CFworks as far back as CF8mostly conventions, someconfigurations necessary
Setup/ConfigurationDownload from
Taffy.ioGithub (github.com/atuttle/Taffy)
Unzip into web root (preferred) or APIsubfolderApplication CFC attribute:extends="taffy.core.api"
Routing
taffy:uri/taffy_uri attribute determinesroute connectionurl: {domain}/api/{players}
component extends="taffy.core.resource" taffy:uri="/players" { //cfc code}
CFC code
SHOW TIME!!!(examples/taffyApplication.cfc andexamples/taffyWideReceiver.cfcin github repo)
ConsiderationsSimple implementationDiverse: CF8+ (& corr. Railo)Well documentedTooling (Dashboard)configuration: known issues w/Tomcat
Enterprise application frameworkconventions baseddiverse and extensibleREST as a module of your application
Setup/Configuration
Preferred workflow: made directory for your appinstall ColdBox & preferred app skeletoninstall RELAX module
Takes roughly a minuteBest Practice: setup all your RESTCFCs in an API module
Routing
SHOW TIME!!!(examples/ColdBoxModuleConfig.cfcin github repo)
CFC code
SHOW TIME!!!(examples/ColdBoxTeam.cfcin github repo)
Unique Considerations
Simple implementationVery extensible within Box familyRELAX as tester & documentationwell documentedRoutes fully customizeableVery little unique code in CFC
Lightweight frameworkconventions basedvery simple, accessibleREST as an application option
Setup/ConfigurationDownload from
fw1.riaforge.orggithub.com/framework-one/fw1coldbox.org/forgebox/view/fw1
setup app in application.cfcset routes/return data
Routing
SHOW TIME!!!(examples/FW1Application.cfcin github repo)
CFC code example
SHOW TIME!!!(examples/FW1kicker.cfcin github repo)
Unique Considerations
Simple frameworksimple route setupVery little unique code in CFC
RecommendationsEvery option worksnon-frameworks vs frameworksapplication architecture style &extensibility
what you wanna do "under the hood"
There is no universal "right option"
REST is not afancy or a gimicTake security seriouslyMake your API robustget Creative!!!
Thank Youhttps://github.com/Francainath/CFSummit-How-We-Rest