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

Parameter Encoding in WSRequest #57

Open
lernamanto opened this issue Sep 11, 2018 · 0 comments
Open

Parameter Encoding in WSRequest #57

lernamanto opened this issue Sep 11, 2018 · 0 comments

Comments

@lernamanto
Copy link

I am using WS to send requests to an API, and my request always fails when the verb is DELETE.

I have digged into it and the reason is that for the DELETE requests the parameters Encoding is always set to "URLEncoding.default", even if in my implementation I try to pass a different one.

In the method is buildRequest() in the WSRequest.swift file, there is this code which sets the encoding to URLEncoding.default for anything else than POST or PUT:

var request: URLRequest?
if httpVerb == .post || httpVerb == .put {
request = try? postParameterEncoding.encode(r, with: params)
} else {
request = try? URLEncoding.default.encode(r, with: params)
}
return request ?? r

I have change this to the following:

var request: URLRequest?
if httpVerb == .post || httpVerb == .put || httpVerb == .delete {
request = try? postParameterEncoding.encode(r, with: params)
} else {
request = try? URLEncoding.default.encode(r, with: params)
}
return request ?? r

And now the DELETE requests work fine.

However when I'll download future updates I'll have to do it again.

Would it not be better to just have this:

var request: URLRequest?
request = try? postParameterEncoding.encode(r, with: params)
return request ?? r

And let the user pass the encoding needed?

Thanks

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

1 participant