How to get request URI in Grails?

I have a simple Grails application with the following RESTful uri ...

http://localhost:8080/kennis-api/funds/test/700

Display in my URIM mappings

 "/funds/test/$fcode" (controller: "fundCache"){
    action = [GET: "show"]
 }

In my controller, I need to extract the request URI, in this case "/ funds / test / 700", but when calling request.uri or request.getRequestUri does not work. I tried using request.requestURL, but that gives me

http: // localhost: 8080 / kennis-api / grails / fundCache / show.dispatch

Is there a special member or function from which to get uri request?

+5
source share
1 answer

Simple, you need the original address, which will be the same as the one where your answer will be sent, it’s easy to save it in the request and you can get:.

String originalURI = request.forwardURI  
//Do this where request is available, ex: Controllers :)
// Everywhere else you can use RequestContextHolder

.
.
,

+6

All Articles