Skip to content

Parameter Encoding in WSRequest #57

@lernamanto

Description

@lernamanto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions