express-reducer
Middleware for express responses.
Express-reducer mutate response json body according to client requirements like graphQL this is will improve client side performance check usage section for more details
Getting started
$ npm install express-reducer
Then in your middleware
const express = const app = const reducer = app
Usage
Just hookup with express and we are good to go
Using with objects and array responses
app
The above route will return entire object but the client just need name and profile_image but creating multiple end points with different response is tedious.
using express-reducer we can solve this issue similar to GraphQL client can pass what they need
client can pass Pluck
keyword as GET parameter along with required object keys
for example
http://api.dev/object?pluck=name,profile_image
response will be look like this
array responses
we can use express-reducer
with array responses
but currently express-reducer
does not support nested reductions
Example
app;
we can filter out these characters based on the family like this
http://api.dev/characters?pluck=stark,targaryen
response will be look like this
See the mocha tests for some more examples.
License
The MIT license
Copyright © 2016 Sarath kumar (sarath.me )