Question

DigitalOcean Functions: How to differentiate query params from body params?

I made a request with the following arguments:

  • Path: /test?potato=true
  • Body: { "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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
August 28, 2022
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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.