5. Age of APIs
✴ Building more APIs than ever
✴ Two distinct concerns:
✴ API
✴ Front-End
✴ Every company is a software company
✴ Agile
✴ Connected
✴ Sustainable
6. API - Version 0
Traditional approaches
✴ Hitting cfm pages and returning JSON
✴ Hitting cfc files ( remote, returnFormat ) = ugly urls
/cfcs/userServiceRemote.cfc?
method=login&email=#email#&password=#password#
✴ Manual Processes
✴ Add status codes manually
✴ Add headers manually
✴ CORS headers manually
✴ Inline Queries Anyone?
✴ No MVC? Homegrown MVC? Old Framework?
✴ No Models? - ie Services, DAOs
✴ No Object Oriented Programming? Ie - Entities
7. We have all been
here!
✴I’ve written APIs like that
✴I still have APIs like that
✴I admit it
I’m scared when I go back to maintain them
I have cried in dark corners
I feel ashamed sometimes
✴How can we do things differently?
✴Modern
✴Functional
✴Fluent
✴But what does that mean?
8. Why Modern Functional and Fluent
✴ More human code
✴ Less boilerplate
✴ Focus on what it should do and not how it should do it
✴ Focus onTesting
✴ Easier to produce
✴ Easier to maintain
✴ Let the tools do the grunt work
✴ But how?
...and dare I say it, FUN!!!
11. API - Version 1
✴ ColdBox App : rest-hmvc template
coldbox create app skeleton=cbtemplate-rest-hmvc@6.0.0-snapshot
✴ Handlers are RestHandlers (ColdBox 6 - Less Boilerplate)
✴ Global Response object (data, errors, status, messages, pagination)
✴ Validating Inputs and returning errors via JSON (Uniformity)
✴ Using Service objects with queryExecute() to return query data
✴ BDDTests
12. API - Version 2
✴ Refactor to use Modern Routing instead of convention routing
✴ Refactor to use array of structs instead of queries
✴ Refactor use structs for gets
✴ CBValidation instead of manual validation
✴ Create an exists() function instead of getting records
✴ Use get() functions for consistency
✴ More BDDTests!
13. API - Version 3
✴ Resourceful Routes
✴ Uniformity on routing
✴ Less Boilerplate
✴ Introduce a BaseService object for encapsulation/abstraction
✴ exists()
✴ existsOrFail()
✴ getOrFail()
✴ Use validateOrFail() for less boilerplate (ColdBox 6)
14. API - Version 4
✴ Using OOP => Created Entities to model my behavior
✴ Better visualization of data
✴ Produce the case-sensitivity I want, instead of ugly UPPER CASE
✴ Encapsulated validation constraints in entities
✴ Encapsulated marshaling of data getMemento()
✴ Services uses a populator to inflate queries to objects
✴ Added pre-handler validation for more encapsulation
15. API - Version 5
✴ Populate Entities with populateModel()
✴ Use Mementifer to stop building data manually
✴ Add a global new() for all services via BaseService.cfc
✴ update(), create() now return the entity
✴ Make your Objects fluent and functional by adding a BaseEntity.cfc
✴ getOrFail()
✴ validateOrFail()
✴ populate()
✴ save()
✴ delete()
✴ Basic memento settings
16. API - Version 6
✴ Make resource parameter type specific to avoid constraints in
preHandler
✴ Make a catch all resource for invalid routing
✴ Event Caching
✴ Add Swagger Docs
✴ Import Swagger Doc into tools
✴ https://editor.swagger.io/
✴ Postman
17. What I didn’t cover?
✴ Resourceful Base Handler with CBORM
✴ Quick ORM - Simplify and Abstract SQL Queries
✴ CBSecurity or CBGuard for annotation based security
✴ CBSecurity for JWT - JSON WebTokens for Stateless Authentication
✴ AutomatedTesting
✴ CI Workflows for testing, generating docs
✴ Linting and Formatting