uws-body-parser

1.0.1 • Public • Published

uws-body-parser

uws-body-parser is a request body parsing middleware for uWebSockets.js.

Typical usage

const { App } = require('uWebSockets.js');

const { bodyParser } = require('uws-body-parser');

const app = App();

app.post('/my/api/endpoint', (res, req) => {
  bodyParser(res, req, (data, wasParsed) => {
      // `wasParsed` argument is a boolean indicating if the body was actually parsed
      if (!wasParsed) {
        console.log('Body not parsed!');
      }
      // `data` argument is the parsed JSON/xWwwFormUrlEncoded/Raw Buffer body
      console.log(data);
      // TODO: your logic here
    }, () => { console.error('request aborted'); }
  );
});

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i uws-body-parser

      Weekly Downloads

      23

      Version

      1.0.1

      License

      MIT

      Unpacked Size

      7.91 kB

      Total Files

      6

      Last publish

      Collaborators

      • guyo13