Controllers
Generating Your Controller
Now that we have created our application, our next step is to create our controllers. Controllers define the business-logic of the Blueprint application, and are a composed from group of actions. The actions of a controller are responsible for servicing requests from clients.
If we look at the original super-rentals tutorial, the mirage component of the tutorial defines the single route GET /api/rentals
. This means that we need an action to handle this HTTP request from the client.
First, let's define our controller. We are going to name the controller rental
since it will be responsible for all business logic related to rentals.
Make sure you run the Blueprint cli from the Blueprint application directory. In this tutorial, you must run the Blueprint cli from the ./super-rentals
directory.
This command will generate an empty controller (i.e., a controller with no actions) named rental
in the ./app/controllers
directory.
Implementing the Action
We can now add our single action to the rental
controller that will get the rentals when requested by a client. The action we create will return the same data as the EmberJS super-rentals example.
That was quite simple!
Next Steps
Now we have a controller that defines an action to respond to client requests for rentals. Our next step is to define a route that invokes this action.
Last updated