this is how we rest

41
How We Rest

Upload: coldfusionconference

Post on 28-Jul-2015

202 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: This is how we REST

How We Rest

Page 2: This is how we REST

Who Am I?@Francainath

Page 3: This is how we REST

This is what I do:

(+ )

(REST)

Page 4: This is how we REST

In the Beginning...

Page 5: This is how we REST

Changing landscape

Page 6: This is how we REST

Where we are today:

Page 7: This is how we REST

PROBLEM:

How can we make our app work on allthese devices?

Page 8: This is how we REST

solution #1: RESPONSIVE DESIGN

Page 9: This is how we REST

solution #2: CUSTOM APPS Unique app for each environment

Page 10: This is how we REST

This requires:

Page 11: This is how we REST

Why REST?When compared to SOAP(Simple Object Access Protocol),REST is considered:

lighter weighteasier to use (for the most part)more flexible

Page 12: This is how we REST

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.

Page 13: This is how we REST

How We Rest5 key options

2 servers

3 frameworks

Page 14: This is how we REST

Natively available in CF10+Uses separate servlet to run RESTRegister your RESTful servicesregister/manage RESTful aspects inCFC via metadata

Page 15: This is how we REST

Setup/Configuration

RestInitApplication(rootPath[,serviceMapping[,options]])

(in application.cfc)

Page 16: This is how we REST

Routing{domain}/rest/{serviceMapping}/{subResource}

Example:{domain}/rest/fantasyFootball/getQuarterback/{id}

Page 17: This is how we REST

CFC code

SHOW TIME!!!(examples/CF10quarterback.cfcin github repo)

Page 18: This is how we REST

Considerations"/rest" mapping

can change this by revising the context path for the RESTservlet in web.xml

Metadata in CFCsAdvocates: truly RESTCritics: verbose, confusing

Page 19: This is how we REST

Natively available in Railo 4+Uses separate servlet to run RESTRegister your RESTful servicesregister/manage RESTful aspects inCFC via metadata

Page 20: This is how we REST

Setup/Configuration

RestInitApplication(rootPath[,serviceMapping[,options]])

(in application.cfc)

Page 21: This is how we REST

Routing{domain}/rest/{service}/{action}{domain}/rest/fantasyFootball/getRunningback/{id}

Page 22: This is how we REST

CFC code

SHOW TIME!!!(examples/RailoRunningBack.cfcin github repo)

Page 23: This is how we REST

Considerations"/rest" mapping

{domain}/rest/{service}/{action}

Metadata in CFCsAdvocates: truly RESTCritics: verbose, confusing

Page 24: This is how we REST

REST focused frameworkDesign: make REST simple for CFworks as far back as CF8mostly conventions, someconfigurations necessary

Page 25: This is how we REST

Setup/ConfigurationDownload from

Taffy.ioGithub (github.com/atuttle/Taffy)

Unzip into web root (preferred) or APIsubfolderApplication CFC attribute:extends="taffy.core.api"

Page 26: This is how we REST

Routing

taffy:uri/taffy_uri attribute determinesroute connectionurl: {domain}/api/{players}

component extends="taffy.core.resource" taffy:uri="/players" { //cfc code}

Page 27: This is how we REST

CFC code

SHOW TIME!!!(examples/taffyApplication.cfc andexamples/taffyWideReceiver.cfcin github repo)

Page 28: This is how we REST

ConsiderationsSimple implementationDiverse: CF8+ (& corr. Railo)Well documentedTooling (Dashboard)configuration: known issues w/Tomcat

Page 29: This is how we REST

Enterprise application frameworkconventions baseddiverse and extensibleREST as a module of your application

Page 30: This is how we REST

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

Page 31: This is how we REST

Routing

SHOW TIME!!!(examples/ColdBoxModuleConfig.cfcin github repo)

Page 32: This is how we REST

CFC code

SHOW TIME!!!(examples/ColdBoxTeam.cfcin github repo)

Page 33: This is how we REST

Unique Considerations

Simple implementationVery extensible within Box familyRELAX as tester & documentationwell documentedRoutes fully customizeableVery little unique code in CFC

Page 34: This is how we REST

Lightweight frameworkconventions basedvery simple, accessibleREST as an application option

Page 35: This is how we REST

Setup/ConfigurationDownload from

fw1.riaforge.orggithub.com/framework-one/fw1coldbox.org/forgebox/view/fw1

setup app in application.cfcset routes/return data

Page 36: This is how we REST

Routing

SHOW TIME!!!(examples/FW1Application.cfcin github repo)

Page 37: This is how we REST

CFC code example

SHOW TIME!!!(examples/FW1kicker.cfcin github repo)

Page 38: This is how we REST

Unique Considerations

Simple frameworksimple route setupVery little unique code in CFC

Page 39: This is how we REST

RecommendationsEvery option worksnon-frameworks vs frameworksapplication architecture style &extensibility

what you wanna do "under the hood"

There is no universal "right option"

Page 40: This is how we REST

REST is not afancy or a gimicTake security seriouslyMake your API robustget Creative!!!

Page 41: This is how we REST

Thank Youhttps://github.com/Francainath/CFSummit-How-We-Rest