json-server
json-server copied to clipboard
Add support of array get params
Proposal
Add support of array get params:
Example:
/comments?id[]=1&id[]=2
jQuery and Axios encoding to arrays by default:
- See: https://github.com/jquery/jquery/blob/master/src/serialize.js#L34
- See: https://github.com/axios/axios/blob/master/lib/helpers/buildURL.js#L42
Unfortunately problem was in another place:
- json-server already supporting arrays
- but son-server doesn't add default express.router middleware (see https://github.com/expressjs/express/blob/master/lib/application.js#L144 where express adding 2 default middleware) to parse query object.
I used next hack to re-parse req.query:
middlewares.unshift((req, res, next) => {
req.query = null;
express.query(server.get('query parser fn'))(req, res, next);
});
Don't know how to fix son-server here (because json-server.router has no access to server object to call server.get('query parser fn'))