Webhook Relay
PricingLogin
  • Introduction
  • Quick Start - Forwarding
  • Quick Start - Tunnels
  • 🛠️Installation
    • Relay CLI
      • Install
      • Auto-start
      • Run config.yaml reference
    • Containerized
      • Kubernetes Installation
      • Podman
      • Docker
      • Docker Compose
  • Products
    • 🛰️Webhook Forwarding
      • Glossary
      • WebSocket Server
      • Authentication
      • Custom Domains
    • ⚡Functions
      • Managing functions
      • Edit request/response
      • Working with JSON
      • 🦾Advanced
        • Working with time
        • Testing functions in CLI
        • Making HTTP Requests
        • Multipart Form Data
        • URLEncoded Form Data
        • GCP BigQuery
        • Sending Emails
        • JWT authentication
        • Base64, Hashes, Encryption
      • 🤖Integrating into CI/CD
    • 🔃Tunnels
      • Using tunnels
      • Custom Domains
      • Encryption (HTTPS)
      • Regions
  • 📝Examples
    • Intro to examples
    • Webhooks
      • Receiving webhooks on localhost
      • Receive webhooks inside your JavaScript app
      • Execute shell scripts on remote machines
    • Functions
      • Enrich webhooks from 3rd party APIs
      • Convert DockerHub webhook to Slack notification
      • Allowing only POST requests through
      • Manipulate webhook request body
    • Tunnels
      • Ingress for any Kubernetes environment
      • Demoing your website
    • 🏠Home Automation
      • Home Assistant
      • Node-RED
      • Raspberry Pi
  • Platform
    • CLI Basics
    • Using CLI Behind Proxy
    • Self-hosting Server
      • Server deployment
      • Client configuration
    • Security & Tech
Powered by GitBook
On this page

Was this helpful?

  1. Products
  2. Functions
  3. Advanced

Multipart Form Data

Some services send data in multipart/formdata encoding. Webhook Relay automatically parses this data and presents it to your function code.

Webhook Relay detects multipart/formdata requests and automatically parses them so your function can use it. Parsed form data can be accessed through r.RequestFormData variable. For example if the payload fragment looks like this:

...
--------------------------5683f7544dff7b07
Content-Disposition: form-data; name="username"

John
--------------------------5683f7544dff7b07
...

Then to get username value (which is John) you will need to:

-- import "json" package when working with JSON
local json = require("json")

-- values can be accessed through 'r.RequestFormData' object. Since 
-- there can be multiple values for each key, you also need to 
-- specify that it's the first element of the list:
local username = r.RequestFormData.username[1]
local first_name = r.RequestFormData.first_name[1]

-- transforming form data into JSON
local json_payload = {
  username = username,
  first_name = first_name
}

local encoded_payload, err = json.encode(json_payload)
if err then error(err) end

r:SetRequestBody(encoded_payload)
PreviousMaking HTTP RequestsNextURLEncoded Form Data

Last updated 3 years ago

Was this helpful?

⚡
🦾