Skip to content

Accessing RequestContext #444

Answered by nmoutschen
niroam asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @niroam !

The RequestContext is an enum, and the actual data could vary based on the source of the call (API Gateway REST, HTTP, or WebSockets APIs, or an ALB). To access the inner data, you'll need to either use if let or match. If you know for sure which variant it will be and don't plan on changing it, I'd recommend using if let.

E.g. with if let:

let req_ctx = request.request_context();

if let RequestContext::ApiGatewayV1(inner_ctx) = req_ctx {
    // Do something with the request context
}

E.g. with match:

let req_ctx = request.request_context();

match req_ctx {
    RequestContext::ApiGatewayV1(inner_ctx) => {
        // Do something with the request context
    },
    RequestC…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nmoutschen
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #443 on March 10, 2022 07:57.