I made a request with the following arguments:
/test?potato=true
{ "banana": true }
In the event, I receive:
{
"banana": true,
"potato": "true",
"__ow_method": "post",
"__ow_headers": {
"accept": "*/*",
"accept-encoding": "gzip",
"cdn-loop": "cloudflare",
"cf-connecting-ip": "xx",
"cf-ipcountry": "BR",
"cf-ray": "xx",
"cf-visitor": "{\"scheme\":\"https\"}",
"content-type": "application/json",
"host": "ccontroller",
"user-agent": "insomnia/2022.4.2",
"x-custom": "okay",
"x-forwarded-for": "xx",
"x-forwarded-proto": "https",
"x-request-id": "xx"
},
"__ow_path": ""
}
My question is: How do I differentiate a query param from a body param?
This way, it’s impossible to know if it’s a query param or a body param, except when the body is formatted in base64
, in which case I get the body inside __ow_body
.
Context: I’m a maintainer of serverless-adapter which integrates serverless clouds with any nodejs framework, I want to add support for Digital Ocean Functions to deploy apps like nestjs, trpc, etc.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
I’ve just checked this internally and when the directive web: raw is not set, the query and body params are promoted to first-class arguments. So you can’t distinguish them within your function.
There is a precedence order and if there are collisions, the body wins.
When the directive web: raw passes the query and body parameters are top-level arguments called
__ow_query
and_body
.The function then has to parse the query string on its own.
Hope that this helps!
Best,
Bobby