How to access the HTTP method within a Ballerina request interceptor

72 Views Asked by At

I'm working with Ballerina and I've implemented a request interceptor for my HTTP service. In this interceptor, I need to access the HTTP method (GET, POST, PUT, etc.) used in the incoming request. I've been going through the documentation and example provided at https://ballerina.io/learn/by-example/http-request-interceptors/

Is it possible to track the HTTP method within a request interceptor in Ballerina, and if so, how can this be achieved? Or is it limited to tracking the path only in the Request Interceptor?

1

There are 1 best solutions below

0
Mindula On

We can access the HTTP method within a Ballerina Request Interceptor using the method field in the http:Request object.

resource function 'default [string... path](http:RequestContext ctx, http:Request req) returns http:NextService|error? {
    string method = req.method;
    // ...
}