Koa 2 ctx.query nesting
See original GitHub issue// When GET /path?a[b]=c
// I think `ctx.query ` should be:
{
a:{
b:'c'
}
}
// But it is
{
'a[b]':c
}
// Is this a bug?
// if it is, I think
// koa/lib/request.js line 11
const qs = require('querystring');
// should replaced by
const qs = require('qs');
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Koa - next generation web framework for node.js
Set query-string to the given object. Note that this setter does not support nested objects. ctx.query = { next: '/login' }; ...
Read more >Getting Request Data with Koa. Query string, originating IPs ...
The ctx.request.query property is also a setter, so we can set it to something else. However, it doesn't support nested objects.
Read more >Building a RESTful API with Koa and Postgres - Michael Herman
This function takes the Koa context as a parameter, ctx . It's worth noting that this object encapsulates both the Node request and...
Read more >Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >next generation web framework for node.js
Koa requires node v7.6.0 or higher for ES2015 and async ... This is useful for adding properties or methods to ctx to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Alternatively, you can use the qs module yourself in a middleware and put the parsed result on the context’s state, i.e.
ctx.state.query = qs.parse(ctx.querystring)
. That’s what I do in my projects.I second @lourd’s approach and would use qs directly instead of going through another npm dependency, especially since it’s not being actively maintained: