krakend / krakend-lua

a lua interpreter for the KrakenD framework
Apache License 2.0
7 stars 14 forks source link

can't get params #12

Closed kmx2 closed 3 years ago

kmx2 commented 3 years ago

make a query: http://192.168.1.31:8080/get_task?id=123
in backend ,configure as below, "github.com/devopsfaith/krakend-lua/proxy/backend": { "pre": "local r = request.load(); print( r:params('id‘) , r:query() ); ...........",

r:params('id‘) result is always "" r:query() result is 'id=123'

why?

kpacha commented 3 years ago

Hi @kmx2 and welcome to the KrakenD community!

The querystring params are not KrakenD params because they are not mandatory. You can pass them to the backend and process/evaluate them with your lua snippets or cel expressions, but not as KrakenD params.

You can find more here: https://www.krakend.io/docs/endpoints/parameter-forwarding/#optional-query-string-forwarding

kmx2 commented 3 years ago

Hi @kpacha thanks for your response. I mean I can get the value 'id=123'' from expression r:query(). but I can't get value ''123'' from expression r:params('id') in lua. I have set "querystring_params":["*"] in endpoint.

kpacha commented 3 years ago

I have set "querystring_params":["*"] in endpoint.

this does not process them as KrakenD params (the ones accessible through the lua params helper), this will just let the querystring to be propagated (making the accessible through the lua query helper).

as said, querystring params are optional so they can't be used as KrakenD params

tobley commented 3 years ago

@kmx2 you might want to try capitalizing the first letter as r:params('Id‘) even though your param might be lowercase {id}. Worked for me.

It's not in the lua section of the docs, but I found it here where it mentions "parameters capitalize the first letter".

I use capitalized first letters for {AnyParam} now to avoid this issue.

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.