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

parameters using encodable #24

Closed
wants to merge 7 commits into from
Closed

Conversation

workingDog
Copy link
Contributor

@workingDog workingDog commented Jan 5, 2021

Added the "extension Encodable" in NetworkingService.swift,
and change "public typealias Params = [String: Any]".
See README (Design a clean api) for how to use.

@s4cha
Copy link
Member

s4cha commented Nov 14, 2023

Hi @workingDog thanks again for taking the time to improve our beloved tool.

Another PR has tackled adding support for Encodable params in 1.2.2
PR62

On top of being able to pass Encodable objects directly, it also passes it via the HTTP body using a json Decoder.
this removes the need for temporarily changing parameter encoding as you pointed out before:

let prevEncoding = network.parameterEncoding
// set the encoding to json
network.parameterEncoding = ParameterEncoding.json
// put back the original encoding when finished
defer { network.parameterEncoding = prevEncoding 
network.post("/articles", params: try article.asParams())

Becomes:

network.post("/articles", body: article)

I hope this still solves your initial use case.
Let me know what you think and we can close this,

As a side note, going forward I'm likely going to emphasize the difference between url (query) params and http body, I feel like the api was a bit blurry with the params. Hopefully I will land a more explicit api for the next major version.

Cheers,

@workingDog
Copy link
Contributor Author

all good. Please close this issue.

@s4cha s4cha closed this Nov 14, 2023
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

Successfully merging this pull request may close these issues.

2 participants