Controllers
Last updated
Last updated
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 , 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.
This command will generate an empty controller (i.e., a controller with no actions) named rental
in the ./app/controllers
directory.
That was quite simple!
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.
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 .