json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Add support of array get params

Open nizsheanez opened this issue 6 years ago • 1 comments

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

nizsheanez avatar May 02 '19 12:05 nizsheanez

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'))

AskAlexSharov avatar Jun 07 '19 06:06 AskAlexSharov