OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

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

Azure Azure Functions Development Webhook
post

This post is over a year old, some of this information may be out of date.

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;

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.

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code