Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

body-reader

1.1.1 • Public • Published

body-reader

Lazy request body stream consumption.

import * as Http from "http";
import * as Parser from "body-reader";
import * as B from "fmt-bytes";
 
Http.createServer((request, response) => {
  Parser.Json.read(
    request,
    { limit: B.toBytes(100, "KiB"), encoding: "utf8" },
    result =>
      result.match({
        Ok(data) {
          response.setHeader("content-type", "application/json");
          response.write(JSON.stringify(data));
          response.end();
        },
        Err(err) {
          response.writeHead(err.code, {
            "content-type": "application/json",
          });
          response.write(JSON.stringify(err));
          response.end();
        },
      })
  );
}).listen({ port: 3000 });

Keywords

none

Install

npm i body-reader

DownloadsWeekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

12.8 kB

Total Files

21

Last publish

Collaborators

  • avatar