How to parse the raw body of a request in a NestJS controller

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • nestjs

    A collection of badass modules and utilities to help you level up your NestJS applications 🚀

  • import { Injectable, NestMiddleware } from '@nestjs/common' import { json } from 'body-parser' /** * Copied this middleware to parse the raw response into a param to use later * from https://github.com/golevelup/nestjs/blob/master/packages/webhooks/src/webhooks.middleware.ts */ @Injectable() export class RawBodyMiddleware implements NestMiddleware { public constructor() {} public use(req: Request, res: Response, next: () => any): any { json({ verify: (req: any, res, buffer) => { if (Buffer.isBuffer(buffer)) { const rawBody = Buffer.from(buffer) req['parsedRawBody'] = rawBody } return true }, })(req, res as any, next) } }

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts