Is there a way to make a GET request in Siesta, while providing parameter, like http://example.com/api/list.json?myparam=1?
I tried with
myAPI.resource("list.json?myparam=1")
but the question mark gets escaped.
Then I tried with
myAPI.resource("list.json").request(.GET, urlEncoded:["myparam": "1"])
but it always fails with "The network connection was lost.", but all other requests succeed, so the message is wrong.
You are looking for
withParam
:The
Service.resource(_:)
method you are trying to use in your first example specifically avoids interpreting special characters as params (or anything except a path). From the docs:This is a security feature, meant to prevent user-submitted strings from bleeding into other parts of the URL.
The
Resource.request(_:urlEncoded:)
method in your second example is for passing parameters in a request body (i.e. with a POST or PUT), not for parameters in the query string.Note that you can always use Service.resource(absoluteURL:) to construct a URL yourself if you want to bypass Siesta’s URL component isolation and escaping features.