Skip to content

hashtaagco/trimbody

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trimbody.js - Request Body trimmer for Express Server

Trim extra spaces on request body for your express / sails app using this middlware.

Getting Started

Installation

Install the package via npm npm install @hashtaagco/trimbody --save

Using

Using this middleware is quite simple like other out there.

var express = require('express')
var trimbody = require('@hashtaagco/trimbody')
var bodyParser = require('body-parser')

var app = express()

// parse various different custom JSON types as JSON
app.use(bodyParser.json())
 
app.use(trimbody)

app.get('/', function (req, res) {
	res.send('hello world')
})


app.post('/test', (req, res) => {
	console.log(req.body)
	res.send(req.body)
})
app.listen(9092)

Now make post request via curl / postman to verify.

curl -X POST -H "Content-Type: application/json" --data '{ "name" : "Anand Siddharth " }' http://localhost:9092/test

Response : {"name":"Anand Siddharth"}.

Observe that the extra space is gone in the key name.

That's all folks

About

Trim extra spaces on request body for your sails app.

Resources

License

Stars

Watchers

Forks

Packages

No packages published