Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building an API with cffractal and ColdBox

Matt Gifford
November 08, 2018

Building an API with cffractal and ColdBox

Matt Gifford

November 08, 2018
Tweet

More Decks by Matt Gifford

Other Decks in Technology

Transcript

  1. > coldbox create module core Created /Users/monkehworks/music_api/modules_app/core Created /Users/monkehworks/music_api/modules_app/core/models Created

    /Users/monkehworks/music_api/modules_app/core/models/models_here.txt Created /Users/monkehworks/music_api/modules_app/core/ModuleConfig.cfc Created /Users/monkehworks/music_api/modules_app/core/views Created /Users/monkehworks/music_api/modules_app/core/views/home Created /Users/monkehworks/music_api/modules_app/core/views/home/index.cfm Created /Users/monkehworks/music_api/modules_app/core/handlers Created /Users/monkehworks/music_api/modules_app/core/handlers/Home.cfc
  2. > coldbox create module core Created /Users/monkehworks/music_api/modules_app/core Created /Users/monkehworks/music_api/modules_app/core/models Created

    /Users/monkehworks/music_api/modules_app/core/models/models_here.txt Created /Users/monkehworks/music_api/modules_app/core/ModuleConfig.cfc Created /Users/monkehworks/music_api/modules_app/core/views Created /Users/monkehworks/music_api/modules_app/core/views/home Created /Users/monkehworks/music_api/modules_app/core/views/home/index.cfm Created /Users/monkehworks/music_api/modules_app/core/handlers Created /Users/monkehworks/music_api/modules_app/core/handlers/Home.cfc
  3. Created modules_app/api Created modules_app/api/models Created modules_app/api/models/models_here.txt Created modules_app/api/ModuleConfig.cfc Created modules_app/api/views

    Created modules_app/api/views/home Created modules_app/api/views/home/index.cfm Created modules_app/api/handlers Created modules_app/api/handlers/Home.cfc > coldbox create module api
  4. Created modules_app/api Created modules_app/api/models Created modules_app/api/models/models_here.txt Created modules_app/api/ModuleConfig.cfc Created modules_app/api/views

    Created modules_app/api/views/home Created modules_app/api/views/home/index.cfm Created modules_app/api/handlers Created modules_app/api/handlers/Home.cfc > coldbox create module api
  5. > cd modules_app/api Created modules_app/api/modules_app/v1 Created modules_app/api/modules_app/v1/models Created modules_app/api/modules_app/v1/models/models_here.txt Created

    modules_app/api/modules_app/v1/ModuleConfig.cfc Created modules_app/api/modules_app/v1/views Created modules_app/api/modules_app/v1/views/home Created modules_app/api/modules_app/v1/views/home/index.cfm Created modules_app/api/modules_app/v1/handlers Created modules_app/api/modules_app/v1/handlers/Home.cfc > coldbox create module v1
  6. > cd modules_app/api Created modules_app/api/modules_app/v1 Created modules_app/api/modules_app/v1/models Created modules_app/api/modules_app/v1/models/models_here.txt Created

    modules_app/api/modules_app/v1/ModuleConfig.cfc Created modules_app/api/modules_app/v1/views Created modules_app/api/modules_app/v1/views/home Created modules_app/api/modules_app/v1/views/home/index.cfm Created modules_app/api/modules_app/v1/handlers Created modules_app/api/modules_app/v1/handlers/Home.cfc > coldbox create module v1
  7. // GET /albums [ { "id": 1, "name": "Be More

    Kind" } … ] // GET /category/rock [ { "id": 1, "name": "Be More Kind", "yearPublished": 2018 } … ]
  8. // GET /albums [ { "id": 1, "name": "Be More

    Kind" } … ] // GET /category/rock { "data": { "albums": [ { "id": 1, "name": "Be More Kind", "yearPublished": 2018 } … ] } }
  9. ARTIST if( variables.consumer == foo ){ if( artist.hasAlbum() ){ result.album

    = artist.getAlbum().getMemento(); } } if( variables.consumer == foo ){ if( album.hasLabel() ){ if( structKeyExists( result, ‘album’ ){ result.album.label = album.getLabel().getMemento(); } } }
  10. Case Study #1 v1 38 API handlers 300 lines of

    code per handler 49 transformers 100 lines of code per handler
  11. WHY CFFRACTAL? Transformers for output control (can be nested) “includes”

    conventions Separation of concern Encapsulation Response consistency Testable components