0.2.2 • Published 25 days ago

@lottojs/body-parser v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
25 days ago

Contributors Forks Stargazers Issues MIT License NPM

About The Project

HTTP Middleware done to parse body parameter from a given request, initially created to serve the @lottojs/router package but nothing excludes it to be also used by the community.

Supported Content-Types:

  • Multipart Form (multipart/form-data).
  • Form URL Encoded (application/x-www-form-urlencoded).
  • JSON (application/json).
  • Text (text/plain).

Documentation

Complete API documentation is available at lottojs.tech.

Getting Started

Installation

 npm i @lottojs/body-parser

Usage

It will depend on your scenario, basically the package exports a middleware called bodyParser. This middleware can be used being called and it returns a promise awaiting to receive a request and next parameters. On the end it put's the parsed body if exists at req.body object, all ready to be used.

    import { createServer } from 'node:http';
    import { paramsParser } from '@lottojs/body-parser';

    createServer(
        async (req: IncomingMessage, res: ServerResponse) => {
                ...
                if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
                    bodyParser()(req, next())
                }
                ...
        },
    )

Contributing

All forms of contributions are more than welcome! You can contribute in the following ways:

  • Create an Issue
  • Create a Pull Request
  • Create third-party middlewares
  • Share with your friends
  • Make your application with Lotto.

For more details, see Contribution Guide.

License

Distributed under the MIT License. See LICENSE for more information.

0.2.2

25 days ago

0.2.1

1 month ago

0.2.0

8 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago