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

how to get body from http request nodejs

Strange Snake answered on April 20, 2021 Popularity 8/10 Helpfulness 1/10

Contents


More Related Answers

  • send a request using node js
  • node http post
  • How to access the request body when POSTing using Node.js and Express
  • javascript get body
  • express get body
  • nodejs request api
  • make a get request in node js
  • node send post request
  • node red http post request data
  • node js http request
  • req.body in express
  • how to use put to request in nodejs
  • how to send response to client in nodejs using res object
  • how to access the req.body
  • how to create request body javascript
  • node js do request
  • request html nodejs
  • get post data in node api
  • http request node.js
  • request get response node js
  • Get Request Node HTTP
  • js add body data to put request
  • nodejs request post
  • get with request body
  • how to make post request to an api node js
  • node fetch response body
  • request body api

  • how to get body from http request nodejs

    -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 8/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

    Closely Related Answers



    0
    Popularity 8/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
    Popularity 10/10 Helpfulness 5/10 Language javascript
    Source: Grepper
    Tags: javascript j
    Link to this answer
    Share Copy Link
    Contributed on Apr 20 2021
    Confused Chamois
    0 Answers  Avg Quality 2/10

    0
    Popularity 9/10 Helpfulness 4/10 Language javascript
    Link to this answer
    Share Copy Link
    Contributed on May 26 2022
    Tomer Mantzuri
    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.