UNPKG

express-partial-response

Version:

Express middleware for filtering-out parts of JSON responses based on the `fields` query-string.

30 lines (26 loc) 638 B
const express = require('express'); const partialResponse = require('../'); const app = express(); app.use(partialResponse()); app.get('/', (req, res) => { res.json({ firstName: 'Mohandas', lastName: 'Gandhi', aliases: [ { firstName: 'Mahatma', lastName: 'Gandhi' }, { firstName: 'Bapu' } ] }); }); app.listen(4000, () => { const prefix = "curl 'http://localhost:4000?fields=%s'"; console.log('Server running on :4000, try the following:'); console.log(prefix, '*'); console.log(prefix, 'lastName'); console.log(prefix, 'firstName,aliases(firstName)'); });