Understanding the HttpContext — Let’s Learn Adonis 5, Lesson 1.3

Tom Gobich | Adocasts.com
5 min readNov 18, 2021

View all lessons in the Let’s Learn Adonis 5 series here.

The HttpContext object is an object that we’ll be heavily working with as we develop our Adonis application. It’s an object that’s going to be provided to us via our middleware, route handlers, HTTP hooks, and exception handlers as we progress throughout our request’s lifecycle.

It’s an object that’s unique to each of our application’s individual requests. So, anytime a user requests a page, submits a form, submits an API request, etc we’ll receive a unique HttpContext object about that user’s request.

HttpContext Mutation Behavior

The way Adonis is going to pass our HttpContext object from one request lifecycle method to the other is by reference. This means that if we mutate our HttpContext object inside our middleware that mutation will remain intact when we receive that request within our route handler.

If an error were then thrown for that request in our route handler, the same mutation we made within our middleware will again be carried through to the exception handler.

--

--

Tom Gobich | Adocasts.com

Learn AdonisJS, NodeJS, JavaScript and more through in-depth lessons, screencasts, and livestreams at adocasts.com