Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

express-detox

1.0.0 • Public • Published

Express Detox

Remove unwanted stuff from your request.body.

Usage

const { only } = require('express-detox');
 
const only_user_params = only('first_name', 'last_name');
 
/*
    POST /
        {
            first_name: 'Nathan',
            last_name: 'Hoad',
            some_other_thing: 'ignored'
        }
*/
 
app.post('/', [only_user_params], (request, response) => {
    // Request Body only has first_name and last_name
    Users.create(request.body).then(user => {
        response.json(user);
    });
});

Nested values

Specify nested values by passing objects to only:

const only_nested_params = only('thing', { nested_thing: ['first', 'second'] });
 
/*
    POST /
        {
            nested_thing: {
                first: 'yes',
                second: 'yes',
                third: 'ignored'
            }
        }
*/

Keywords

none

install

npm i express-detox

Downloadsweekly downloads

5

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability