Networking icon indicating copy to clipboard operation
Networking copied to clipboard

parameter using encodable

Open wlgemini opened this issue 5 years ago • 4 comments

something like this:

func post<T: Encodable>(params: T) { ... }

wlgemini avatar Jul 22 '20 06:07 wlgemini

@wlgemini this is a good idea. Could you give a concrete example of some data you would want to pass ?

s4cha avatar Jul 22 '20 13:07 s4cha

struct Account: Encodable {
    let email: String
    let password: String
}

struct UserInfo: Decodable { ... }

struct Api: NetworkingService {

    func login(account: Account) -> AnyPublisher<UserInfo, Error> {
        post("/login", params: account)
    }
}

wlgemini avatar Jul 24 '20 05:07 wlgemini

@wlgemini Thanks for the concrete example this indeed looks like something we want to support. Pretty busy at the moment but if you want to take a crack at it through a PR in the meantime, feel free to do so :)

s4cha avatar Aug 03 '20 07:08 s4cha

I've created a possible solution to "parameters using encodable" in my fork branch "encodable".

  https://github.com/workingDog/Networking/tree/encodable

Basically added the "extension Encodable" in NetworkingService.swift, and change "public typealias Params = [String: Any]"

See README -> "Design a clean api" -> "CRUDApi" for how to use.

It would be good if someone could test this and report back.

workingDog avatar Dec 03 '20 00:12 workingDog