luraproject / lura

Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
https://luraproject.org
Other
6.35k stars 564 forks source link

[ASK] - Change Key Name In Query String #290

Closed FerdinaKusumah closed 4 years ago

FerdinaKusumah commented 5 years ago

Krakend Endpoint [GET] - http://localhost:8000?key=xxxx Backend URL [GET] - http://xxx.api.com?token={key} How can i change query string name from key to token like this ?

Thank you

kpacha commented 5 years ago

querystring are not mandatory params, so you can't go with the param mapping, but you can play with the request querystring with a small lua script. check out this example against the deuig endpoint:

{
    "version": 2,
    "port": 8080,
    "endpoints": [
    {
        "endpoint": "/",
        "querystring_params": ["token"],
        "backend": [
            {
                "host": [ "http://localhost:8080" ],
                "url_pattern": "/__debug"
            }
        ],
        "extra_config": {
            "github.com/devopsfaith/krakend-lua/router": {
                "pre": "local req = ctx.load() ; req:query(\"token\", req:query(\"key\")) "
            }
        }
    }]
}
[GIN-debug] redirecting request 301: /__debug --> /__debug/?&token=supu
2019/10/01 17:59:06  DEBUG: Method: GET
2019/10/01 17:59:06  DEBUG: URL: /__debug/?&token=supu
2019/10/01 17:59:06  DEBUG: Query: map[token:[supu]]
2019/10/01 17:59:06  DEBUG: Params: [{param /}]
2019/10/01 17:59:06  DEBUG: Headers: map[Accept-Encoding:[gzip] Referer:[http://localhost:8080/__debug?&token=supu] User-Agent:[KrakenD Version 1.0.0] X-Forwarded-For:[::1]]
2019/10/01 17:59:06  DEBUG: Body:
[GIN] 2019/10/01 - 17:59:06 | 200 |     201.654µs |             ::1 | GET      /__debug/?&token=supu
[GIN] 2019/10/01 - 17:59:06 | 200 |       2.261ms |             ::1 | GET      /?key=supu

But if you require a querystring to be present, you should also add some verification to the pipe...

github-actions[bot] commented 2 years ago

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.