Skip to content
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

Get query string from a request #45

Closed
bohdankoshyrets opened this issue Oct 24, 2018 · 2 comments
Closed

Get query string from a request #45

bohdankoshyrets opened this issue Oct 24, 2018 · 2 comments

Comments

@bohdankoshyrets
Copy link

I'm trying to get the query string arguments from an URL similar to: /v2/users?direction=past&limit=20. Is there a way to get those parameters and their values inside a router to form response based on those parameters? I did try to use URLParametersReader, but it returns an empty object every time.

@fangpenlin
Copy link
Contributor

@bohdankoshyrets yep, there's a way you can use it, here's the example

let query = environ["QUERY_STRING"] as! String
let params = URLParametersReader.parseURLParameters(query)
let paramsDict = MultiDictionary<String, String, NoOpKeyTransform<String>>(items: params)
print(paramsDict["direction"])
print(paramsDict["limit"])

@bohdankoshyrets
Copy link
Author

Yep, this works perfectly. Once again, thank you, @fangpenlin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants