Question

POST input to a Serverless Function

Hello all. Following the documentation on Serverless Functions, it is demonstrated how to pass over input arguments into the function handler (the ‘args’ for the ‘main()’ function. It is shown and explained that the parameters can be passed as query strings (i.e. GET method) and retrieved in the handler using the ‘args’ object. Is there a way to also pass such input parameters using POST? For instance, listening to PayPal webhook require POST acceptance. Also, passing over a large base64 input (image/audio) does not make sense as a GET parameter. How can these be accepted and retrieved within the main(args) handler, both for a web function as well as internal call. Thanks!


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
March 6, 2024

Hey!

Yes, that should be doable as described here:

https://docs.digitalocean.com/products/functions/reference/parameters-responses/#event-parameter

  • web: true: This is the default mode. Query string parameters and the request body are parsed and added as top-level keys in the event dictionary.
  • web: raw: The HTTP request body and query string are included as-is instead of being parsed.
  • web: false: No web event is included at all.

The default web: true event is structured like the following JSON example:

{
  "http": {
    "headers": {
      "accept": String,
      "accept-encoding": String,
      "content-type": String,
      "user-agent": String,
      "x-forwarded-for": String,
      "x-forwarded-proto": String,
      "x-request-id": String
    },
    "method": String,
    "path": String
  },
  [String]: any
}

Let me know how it goes!

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.