Skip to content

Access Http context in the class #3280

Answered by MaximeMRF
farshadfahimi asked this question in Help
Discussion options

You must be logged in to vote

Hello,
I think you should read the Controllers guide.
If you want to access the http context the following code will help you.

import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class Test {
  public static verify(ctx: HttpContextContract) {
    console.log(ctx)
  }
}

Or if you want just to access the request:

import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class Test {
  public static verify({ request }: HttpContextContract) {
    console.log(request)
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MaximeMRF
Comment options

Answer selected by farshadfahimi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants