Moya: Missing case in Task enum
In one of my projects, I needed to use the parameters in the query string, and also use the body. Due to the fact that the property path can not be represented as:
public var path: String {
switch self {
case .myCase(let name): return "api/endpoint?username=\(name)"
}
Here’s what my case should look like:
case requestJSONEncodable(Encodable, parameters: [String: Any], encoding: ParameterEncoding)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (13 by maintainers)
Commits related to this issue
- Adds note from #1647. — committed to Moya/Moya by ashfurrow 6 years ago
- Adds note from #1647. — committed to Moya/Moya by ashfurrow 6 years ago
- Adds note from #1647. (#1659) — committed to Moya/Moya by ashfurrow 6 years ago
@ashfurrow @SD10 @sunshinejr I need case for Encodable body and parameters as queryString. Because “api/endpoint?username=(name)” in path property not working due to encoding. And even if it worked, the solution is very bad, i think.
None of them allow us to use Encodable + [String: Any] as url parameters. Sure i can use:
But I do not think this is a good decision. Because, this is not the place where we need to encode Encodable to data.
Update my proposal case:
@SD10 There is no need to apologize! We can work through these things together as they come up – and things like this do come up, for every project.
Could this be something that Parameter Encoding solves? We have docs here: https://github.com/Moya/Moya/blob/master/docs/Examples/ParameterEncoding.md Basically you can provide a custom bit of code that translates the parameters of the endpoint into the request. Again, a bit of a clutch, but as pointed out this is an uncommon scenario.
Moya should make common things easy and uncommon things possible, and a “clutch” in this case might be worth it for the sake of a smaller API surface area.