Access Http context in the class #3280
Answered
by
MaximeMRF
farshadfahimi
asked this question in
Help
-
I have a simple class like below and need to acces import HttpContext from '@ioc:Adonis/Core/HttpContext'
class Test {
public static verify() {
const ctx = HttpContext.get()
console.log(ctx) // null
}
} I need to access the |
Beta Was this translation helpful? Give feedback.
Answered by
MaximeMRF
Oct 25, 2021
Replies: 1 comment 1 reply
-
Hello, 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 import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class Test {
public static verify({ request }: HttpContextContract) {
console.log(request)
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
farshadfahimi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I think you should read the Controllers guide.
If you want to access the
http context
the following code will help you.Or if you want just to access the
request
: