Search⌘ K
AI Features

Controllers

Explore how controllers in AdonisJs handle application logic by responding to HTTP requests. Understand the use of HTTP context for accessing request and response objects in routes and controllers, and learn techniques for organizing controller code.

We'll cover the following...

Controllers are files that handle application logic and are associated with models, views, helpers, etc. Controllers are created to respond to HTTP requests and are not meant to be included in other files. We should try to refactor controllers into separate files to avoid messy controller code.

Creating a controller

'use strict'

class TestController {
  hello(){
    return 'Hello from Controller'
  }
}

module.exports = TestController
...