DEV Community

Elio Struyf
Elio Struyf

Posted on • Originally published at eliostruyf.com on

Parse application/x-www-form-urlencoded in Azure Function

For a Mailchimp webhook, I had to parse the application/x-www-form-urlencoded form data to JSON. Azure Functions does not automatically do this for you, so you have to provide your parser. I knew that I had already done this, so I went on a search journey through my code.

To make it easier next time, I wanted to share the code snippet with the rest of you. As you will notice, there isn't a lot of code required.

import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { parse, ParsedQs } from 'qs';

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
  if (req.rawBody) {
    const parsedData: ParsedQs = parse(req.rawBody);

    context.res = {
      body: parsedData
    };
  }

  context.res = {
    body: 'No raw body data'
  };
};

export default httpTrigger;
Enter fullscreen mode Exit fullscreen mode

This code snippet makes use of the qs (querystring) dependency. To install this dependency to your project, all you need to do is: npm i qs -S -E.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more