© Christopher Pitt 2018
Christopher PittThe Definitive Guide to AdonisJshttps://doi.org/10.1007/978-1-4842-3390-0_8

8. Controllers and Middleware

Christopher Pitt1 
(1)
Cape Town, Western Cape, South Africa
 

In the previous chapter, we wrapped up the theory behind async and await. Let’s get back to the main Threadbear application, beginning with a reorganization of code!

In this chapter, we’re going to learn about controllers and middleware. These are two powerful concepts for organizing and reusing code. The first will help us to slim down our routes file, and the second will help us to add reusable things such as authentication and content-negotiation features.

Making Controllers

So far, we’ve been putting all of our request and response code into the ...

Get The Definitive Guide to AdonisJs: Building Node.js Applications with JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.