By H4ad
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!
Accepted Answer
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.