Skip to content

sugojs/sugo-body-parser-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published