-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0.0 plan #5
Comments
I don't want to write codes like these any more. var val = this.query.foo;
if (Array.isArray(val)) {
// ...
} else {
// ...
} |
What are you going to use as a query string parsing library? I think @dougwilson and i had plans for a new query string parser. I personally wish it was always a string. If you want types, you should be using JSON! |
@jonathanong yep, I personally only using string value. But other users want more value type, and I want to help them use querystring more easy and safely.
|
Really nice @fengmk2. Wholeheartedly agree that Btw, reminds me of https://blogs.dropbox.com/developers/2015/03/json-in-urls/. |
@jonathanong yea, I would like to get a query parsing lib in |
@ruimarinho current How about @dougwilson new |
What about |
I don't like |
@dead-horse @hotoo @ruimarinho how about this |
i'm guessing you guys want to make a module first, right? Something like: const query = Query(this.querystring);
let value = query.get(key, options); |
@jonathanong yep, for the experienced node.js developer he/she can use module way. But most new node.js developers inside my team, I need to make sure they use a same way and don't want them to care about which version of let value = this.getQuery(key, options); |
I think // foo[bar][baz]=foobarbaz => this.queryObject.foo return { bar: { baz: 'foobarbaz' } }
// developer write code following:
var baz = this.queryObject.foo.bar.baz;
// if there not has `foo[bar][baz]` key in querystring, will throw javascript exception.
// developer must write code like following for safe:
var baz;
if (this.queryObject.foo && this.queryObject.foo.bar) {
baz = this.queryObject.foo.bar.baz;
}
if (typeof baz !== "undefined") {
// dosomething.
} |
Just provide |
|
@hotoo your proposal look better 👍 |
let's get this started! https://github.com/pillarjs/qs-strict |
Could you please implement middleware pattern?
|
👍 for the middleware pattern. It would allow it to be configured in a koa-router route instead of at the root. |
Any plans to upgrade the version for qs? |
@fengmk2 I think it is unacceptable. I prefer to use There is a scenario that any middleware could change the |
@adoyle-h No, |
Closing, feel free to reopen |
request.query and request.queries
Make
request.query[key]
return strictString
value and addrequest.queries[key]
to returnArray
value.ctx.query
torequest.query
ctx.queries
torequest.queries
request.query[key]
return
String
valueundefined
foo[bar][baz]=foobarbaz
=>{ 'foo[bar][baz]': 'foobarbaz' }
request.query.foo
returnundefined
request.query['foo[bar][baz]']
return'foobarbaz'
a[]=b&a[]=c
=>{ 'a[]': 'b' }
request.query.a
returnundefined
request.query['a[]']
returnb
a=b&a=c
=>{ 'a': 'b' }
request.query.a
returnb
request.queries[key]
return
Array
valueundefined
foo[bar][baz]=foobarbaz
=>{ 'foo[bar][baz]': [ 'foobarbaz' ] }
request.queries.foo
returnundefined
request.queries['foo[bar][baz]']
return[ 'foobarbaz' ]
a[]=b&a[]=c
=>{ 'a[]': [ 'b', 'c' ] }
request.queries.a
returnundefined
request.queries['a[]']
return['b', 'c']
a=b
=>{ 'a': [ 'b' ] }
request.queries.a
return['b']
a=b&a=c
=>{ 'a': [ 'b', 'c' ] }
request.queries.a
return['b', 'c']
The text was updated successfully, but these errors were encountered: