41
How We Rest

How we rest

Embed Size (px)

DESCRIPTION

Nathaniel Francis How we REST

Citation preview

Page 1: How we rest

How We Rest

Page 2: How we rest

Who Am I?@Francainath

Page 3: How we rest

This is what I do:

(+ )

(REST)

Page 4: How we rest

In the Beginning...

Page 5: How we rest

Changing landscape

Page 6: How we rest

Where we are today:

Page 7: How we rest

PROBLEM:

How can we make our app work on allthese devices?

Page 8: How we rest

solution #1: RESPONSIVE DESIGN

Page 9: How we rest

solution #2: CUSTOM APPS Unique app for each environment

Page 10: How we rest

This requires:

Page 11: 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: 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: How we rest

How We Rest5 key options

2 servers

3 frameworks

Page 14: How we rest

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

Page 15: How we rest

Setup/Configuration

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

(in application.cfc)

Page 16: How we rest

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

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

Page 17: How we rest

CFC code

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

Page 18: 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: 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: How we rest

Setup/Configuration

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

(in application.cfc)

Page 21: How we rest

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

Page 22: How we rest

CFC code

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

Page 23: How we rest

Considerations"/rest" mapping

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

Metadata in CFCsAdvocates: truly RESTCritics: verbose, confusing

Page 24: How we rest

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

Page 25: 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: 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: How we rest

CFC code

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

Page 28: How we rest

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

Page 29: How we rest

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

Page 30: 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: How we rest

Routing

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

Page 32: How we rest

CFC code

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

Page 33: How we rest

Unique Considerations

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

Page 34: How we rest

Lightweight frameworkconventions basedvery simple, accessibleREST as an application option

Page 35: 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: How we rest

Routing

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

Page 37: How we rest

CFC code example

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

Page 38: How we rest

Unique Considerations

Simple frameworksimple route setupVery little unique code in CFC

Page 39: 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: How we rest

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

Page 41: How we rest

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