140 likes | 226 Views
Writing remote API's. w ith ColdBox and REST. Kalen Gibbons. President of Sercossa Inc. A member of Team ColdBox. Co-Manager of IECFUG Flex, ColdFusion, JavaScript Developer. Value of the Model. Data is the most important part of your application. Exposing your model.
E N D
Writing remote API's with ColdBox and REST
Kalen Gibbons • President of Sercossa Inc. • A member of Team ColdBox Co-Manager of IECFUG Flex, ColdFusion, JavaScript Developer
Value of the Model Data is the most important part of your application
Exposing your model • The web is evolving • Heavier front-end applications • Mobile • Frequent integrations • Requires more options • Standard page view (PV) model • REST (JSON, XML, etc) • AMF (raw data for Flash/Flex) • Many others
Using REST Representational State Transfer
Creating Routes • Config/routes.cfm • addRoute(pattern="/customers", handler="remote.customers", action={GET="getAllCustomers"}); • HTTP Verbs • GET, POST, PUT, DELETE • Can use existing handlers • But typically need to customize results
Creating Handlers • Handlers know who to talk to • Use a base handler to make life easy • PreHandler : prepares data • PostHandler : marshals data • Exception Handling is required • Errors must be returned in the correct format • OnError : Handles exceptions and marshals data
Exposing Data In new ways
Example: AMF API’s • Action Message Format for Flash/Flex • Binary format for serializing CF objects to ActionScript • Acts like a plain CFC method invocation • Uses ColdBox Proxy to enable the full ColdBox Request Life Cycles • Allowing interceptors, AOP, etc. to work normally • Can extend remote functionality to suite needs
Architectural Considerations Creating a reusable model
What are Handler for? • Handler are Controllers • They know what data is required • They know who to talk to • Handlers are NOT for: • Business logic • Data processing • Mixing logic in your handles creates duplication
Example Handlers with logic Leveraging services Security Logging Error Handling Data manipulation Security Logging Error Handling Data manipulation Security Logging Error Handling Data manipulation Security Logging Error Handling Data manipulation
A Better Architecture Business Services Data Services SQL Database SAP REST Service Other Sources
Thanks Kalen@Sercossa.com @KalenGibbons