1.0.3 • Published 5 years ago

@sugo/body-parser-json v1.0.3

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

@sugo/body-parser-json

Middleware for parsing Json type requests

How to install

npm install --save @sugo/body-parser-json

getSuGoJsonBodyParserMiddleware

Builds the middleware.

Example - Node Http Server

import getParseJsonBody, { IRequest } from '@sugo/body-parser-json';
const parseJsonBody = getParseJsonBody();
const server = http.createServer(async (req: IRequest, res: http.ServerResponse) => {
  await parseJsonBody(req, res);
  res.writeHead(200, headers);
  res.end(JSON.stringify(req.body));
});

Example - SuGo Server

import { createServer, SuGoRequest, SuGoResponse } from '@sugo/server';
import getParseJsonBody, { IRequest } from '@sugo/body-parser-json';
const parseJsonBody = getParseJsonBody();
const server = createServer((req: SuGoRequest, res: SuGoResponse) => {
  res.writeHead(200, headers);
  res.end(JSON.stringify(req.body ? req.body : {}));
}).useMiddleware(parseJsonBody);
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago