@sdk_cy/body-parser

A simple parser middleware to parse JSON or urlencoded body data for express or @sdk_cy/tiny-server

Usage no npm install needed!

<script type="module">
  import sdkCyBodyParser from 'https://cdn.skypack.dev/@sdk_cy/body-parser';
</script>

README

@sdk_cy/body-parser

@sdk_cy/body-parser is a body parser middleware which it can be used with express or @sdk_cy/tiny-server It can parse json or x-www-form-urlencoded data from your request.

Installation

Use the package manager npm to install body-parser.

npm install @sdk_cy/body-parser

Usage

const tiny = require("@sdk_cy/tiny-server"); //You can use express
const bodyParser = require("@sdk_cy/body-parser");
const port = 8000;
const app = tiny();

app.use(bodyParser);

app.post("/", (req, res) => {
    //This endpoint now accept json or x-www-form-urlencoded
    res.setHeader("Content-Type","application/json");
    return res.status(200).send(JSON.stringify(req.body));
});

app.listen(port, (err) => {
    if (err) {
        return console.log('Error: ', err)
    }
    console.log("Server is listening on ", port)
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT