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
query string "?" passed in via "at:" parameter is encoded to "%3F" #22
Comments
To use query parameters, you will need to use Apple's URL/URLComponents API instead of using a raw string. A quick sample may look something like this (excuse all the force unwrapping...just a very quick, sloppy example). let baseURL = URL(string: "http://httpbin.org/get")!
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)
components!.queryItems = []
components!.queryItems?.append(URLQueryItem(name: "name", value: "Bob"))
let rest = RestController.make(url: components!.url!) |
However by doing the suggested method, I can no longer use 1 RestController for all my calls. Every time when query string is required, I need to create a new RestController which go against the suggested usage of using only 1 RestController for every the calls as mention in your notes:
|
The main concern (minor concern anyways) is continually creating a new URL object form a String. If you define the base URL object in your project then make a new RestController using the new URL, it'll be fine. As of now, that is the only way to do GET parameters. Feel free to create a pull request that adds an optional [URLQueryItem] object to the GET calls, that way you could use a single RestController and pass in different query items. I do not know when I'll get around to doing it, but it is on my list to do in a future update. |
Also, given all RestControllers use the shared NSURLSession, creating multiple of them is not a huge concern. At one point, I toyed with the idea of allowing you to specify a new URLSession; however I never allowed that because it made the API too messy. If I did that, then you definitely would want to stay away from creating too many. |
Hi, I been experiencing issue when trying to use the get function in the RestController to retrieve a list. The "at:" parameter when passed in with query string, will auto encode the "?" to "%3F" and cause my spring framework server to read the entire query string as part of the URL path literal instead.
Below is my code snippet of my calls:
rest.get(withDeserializer: JSONDeserializer(), at: "/list?page=0&size=10&sort=name,asc", options: header, callback: {result, response in print("\(result)\n\n\(response)"})
the url that was called (copied from response print) as: http://localhost:8095/itam/api/asset/list%3Fpage=0&size=10&sort=name,asc
I have tested the server call to be working using the "?" instead of "%3F" via postman chrome extension.
Is it possible not to encode the "?" or provide a query string parameter so that the query string doesn't get encoded?
The text was updated successfully, but these errors were encountered: