Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

read body of post request nodejs

Confused Chamois answered on April 20, 2021 Popularity 10/10 Helpfulness 5/10

Contents


More Related Answers

  • node express post request json
  • How to parse POST requests with express nodejs
  • node http post
  • express post body
  • How to access the request body when POSTing using Node.js and Express
  • body-parser node
  • express get body
  • node send post request
  • nodejs bodyparser form data
  • node.js express post query string
  • node red http post request data
  • express request post body form
  • node js post method
  • How to use body-parser in node js
  • express receive post data
  • req.body in express
  • http get response body node js
  • how to create request body javascript
  • express json body
  • get post data in node api
  • expressjs req.body.parameters
  • why use body parser express
  • node express query string body parser
  • js add body data to put request
  • nodejs request post
  • node js http post request
  • get with request body
  • how to make post request to an api node js

  • read body of post request nodejs

    1
    Popularity 10/10 Helpfulness 5/10 Language javascript
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Apr 20 2021
    Confused Chamois
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0
    Popularity 9/10 Helpfulness 6/10 Language javascript
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Sep 11 2023
    YOU.com
    0 Answers  Avg Quality 2/10

    -1

    // File: `pages/api/webhooks/someProvider.ts`

    import type { NextApiRequest, NextApiResponse } from 'next';

    import type { Readable } from 'node:stream';

    // EXPORT config to tell Next.js NOT to parse the body

    export const config = {

    api: {

    bodyParser: false,

    },

    };

    // Get raw body as string

    async function getRawBody(readable: Readable): Promise {

    const chunks = [];

    for await (const chunk of readable) {

    chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);

    }

    return Buffer.concat(chunks);

    }

    // API handler function

    export default async function handler(req: NextApiRequest, res: NextApiResponse) {

    const rawBody = await getRawBody(req);

    console.log('raw body for this request is:', rawBody);

    const data = JSON.parse(Buffer.from(rawBody).toString('utf8'));

    console.log('json data for this request is:', data);

    res.send('Got raw body!');

    }  

    Popularity 9/10 Helpfulness 1/10 Language javascript
    Link to this answer
    Share Copy Link
    Contributed on Jun 02 2023
    Strange Snake
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.