
A brief introduction of the course and the instructor's professional background
A presentation of the course deliverables
Read the attached pre-requisites documentation
Get familiar with the VS Code IDE
Create a cbox3 project in your IDE
Unzip the content of the attached cbox3.zip under the project root
Launch Commandbox
Test a database instance connection with your MySQL client
Read the project-config documentation
Install the RESTful Coldbox API template
Verify config/Coldbox.cfc settings
Install additional modules
Update Application.cfc
Update the dot env file
Edit server.json file
Create a password to access Lucee (CFML) server administration
Verify datasource and MySQL connection
Start/Stop the CFML server to verify your configuration
Make a backup of your own server.json file
Keep a copy of your own dot env file as dot.env.example file
Pre-installed model components
Pre-installed handler components
Pre-installed apidocs folder
Run pre-installed components unit tests
Run pre-installed components integration tests
Create a user to run our queries
Update config/Coldbox.cfc custom settings
initiate schema migration
Review the entity relationship diagram
Create empty migration files
Create tab_currency
Create tab_country
Create tab_city
Create tab_airport
Commit components to the database schema
Rollback components from the database schema
Update tab_currency with seed data
Update tab_country with seed data
Update tab_city with seed data
Update tab_airport with seed data
Commit updated components to the database schema
Review the entity relationship diagram
Create empty fk_constraints migration file
Write referential integrity constraints
Commit foreign key constraints to the database schema
Review the schema.xml file
Review the LoadXMLschema.cfc component
Update config/Wirebox.cfc
Review LoadSchemaTest.cfc
Run LoadSchemaTest.cfc
Create Airport.cfc
Create City.cfc
Create Country.cfc
Create Currency.cfc
Create AirportTest.cfc
Create CityTest.cfc
Create CountryTest.cfc
Create CurrencyTest.cfc
Run all entities unit tests
Review the BaseService.cfc parent component
Create AirportService.cfc
Create CityService.cfc
Create CountryService.cfc
Create CurrencyService.cfc
Create AirportServiceTest.cfc
Create CityServiceTest.cfc
Create CountryServiceTest.cfc
Create CurrencyServiceTest.cfc
Run all services unit tests
Update config/Router.cfc with the Currency API routes
Update config/Router.cfc with the City API routes
Update config/Router.cfc with the Country API routes
Update config/Router.cfc with the Airport API routes
Show the Coldbox route-visualiser
Create the CountryAPI.cfc component
Create a CountryAPITest.cfc component
Run the integration test
Currency API handler
City API handler
Airport API handler
Currency API integration test
City API integration test
Airport API integration test
Document API response json components
Link responses to API handlers annotations
Update config/Coldbox.cfc (set cbSwagger development server URL)
Download the free Swagger Editor (a.k.a OpenAPI Editor) to your desktop
Use Coldbox cbSwagger module to generate a json formatted output of our API documentation
Copy the entire cbSwagger output and paste it in the Swagger Editor
Accept the prompt to generate an openapi.yaml file
Place this downloaded file in the resources/apidocs folder
Download the free Postman REST client
Configure POSTMAN environment
Import the resources/apidocs/openapi.yaml file (generated in the previous lecture)
Select the collection and test the API responses
Export a Postman collection file to the resources/apidocs folder
A summary of what you have learnt with this course
We are going to build a Coldbox REST API and test it using the TestBox module. We shall document this API by adding annotations to our API handlers. We'll then use the Coldbox cbSwagger module to generate our API documentation in the Swagger Editor. Finally, we'll use Postman to input data in order to simulate API responses from calls to our development server.
Please note however, that it is not in the scope of this course to explain Swagger Editor and Postman tools in detail. Also note that API security issues using Coldbox cbSecurity and JWT (Json Web Tokens) won't be discussed in this course. Last and not least, we won't build and connect a javaScript front-end to this server-side API.
We are first going to add tables to our MySQL database schema called Merapi (4 tables altogether) , build relationships between those tables and populate our tables with seed data with the help of Coldbox cfmigrations module. This database schema manages data about Countries, Currencies, Cities and Airports. The cfmigrations module was already covered in detail in my two earlier tutorials, but will be covered again at the beginning of this tutorial and documented in the guide provided with it.
Next, we are going to build our model and map our entity class property names to our tables columns name using an XML schema file representing the database schema. We'll also have an XML Loader file to read the XML schema, thus implementing a simple custom object relational mapper. This approach is an alternative, to what we demonstrated in another course called Tamarind v1, in which we used Quick ORM to map entity object properties to table columns and to load entities in memory. Therefore, in this course, no ORM is involved.
We also leveraged object inheritance with the creation of a BaseService parent component. Like a DAO (Data Access Object), this component provides an abstraction of our queries for READ, DELETE and record filtering methods. This way, there is no need to write those queries again in the children components. We simply call the relevant method from the BaseService parent component with the Super keyword.
To make sure that our model entity and services are fully functional, we shall use the Testbox module to write unit tests. After completing our model entity and service components and making sure all our unit tests pass, we shall focus on building the API itself. The API is going to deal with two types of things: the API handlers and the API documentation.
The handlers are composed of actions (index, show, create, update and delete). As we write our handlers, we shall also write the corresponding integration tests that guarantee that our handlers are working fine. Integration tests will also be written with Testbox.
The API documentation is composed of json files such as responses, requestBody, parameters and examples that apply to each handler's action based on an API response such as 2xx (Success), 4xx (Not found or validation error) or 5xx (Server error). A pointer to each of these json files found in the /apidocs folder, will be added as an annotation to the handler's action code. Thanks to this, our API documentation will become immediately exportable to tools such as Postman or OpenAPI (Swagger).
Once this is done, we shall leverage the Coldbox cbswagger module to generate an output as we hit our development server url at cbswagger. Copying and pasting this cbwagger output in our Swagger Editor will not only deliver a colourful and neat documentation of our API, but also generate an openAPI.yaml file that we can then import into Postman. Postman is a tool that allows further testing of our API server with real data.
At the end of the course, you should have acquired a solid and practical understanding as how to build a server-side REST API with the Coldbox framework.