Moya / Moya

Network abstraction layer written in Swift.
https://moya.github.io
MIT License
15.15k stars 1.99k forks source link

Thrift/gRPC generator for Moya #1401

Open AndrewSB opened 7 years ago

AndrewSB commented 7 years ago

Hey, I'm working on a side project (finally, iOS) and I want to use Moya, but I've also wanted to try out this rpc framework called Thrift.

I don't know if this will be useful -- maybe something like thrift replaces Moya, or maybe I should just manually re-implement the core of Moya to wrap these blocking thrift network requests instead. I'm not sure yet.

I thought this issue would be a good scratch pad for me to report back my findings and get input from you guys: @sunshinejr, @SD10, @BasThomas. Maybe even @orta and @ashfurrow? This is quite similar to #73, which I remember you guys being interested in.

For thrift, I'm using this fork of thrift that added Swift support last year.

I think I'm going to start out by re-implementing the core of Moya and wrapping my thrift calls in there

BasThomas commented 7 years ago

Super exciting! Very interested in what you come up with. No doubt you'll spot some improvements that we can get in Moya itself. Looking forward to what you create. Let me know if I can help in any way :)

AndrewSB commented 7 years ago

I'm admittedly a little rusty with Moya, but I'm trying to make a single request method that uses the type in the enum as it's return type.

Is something like this possible? I remember seeing discussion in #948, #950, and #1061.

screen shot 2017-10-24 at 11 44 52 am I'm trying to fill out the request method right now

SD10 commented 7 years ago

@AndrewSB Thanks for starting this discussion 👍 I am a bit confused as to what you're trying to accomplish. Are we talking about having network requests that return decoded objects instead of the response?

sunshinejr commented 7 years ago

@AndrewSB I was trying to do something similar for Moya, but I'm afraid it is not possible (and it is rather a Swift issue). Basically you want a generic method, but you are returning concrete types, instead of given generic ones. But if somehow you manage to get this nice API in, I would love to see it.

SD10 commented 7 years ago

I'm really anxious to discuss this more because I built something similar for my own networking layer (based on Moya) a few months back. I never made the suggestion because I thought it was out of scope.

Unfortunately, I deleted the project in a recent cleanup 😭 It is possible but like @sunshinejr mentioned a nice API is key. I had a critical design decision where I either had to make TargetType generic or lean too heavily on Any. I think I also explored some sort of type eraser / wrapper object.

@AndrewSB Can you make that returnType property return something like an AnyDecodable wrapper?

We need a way of specifying which types can be decoded from a TargetType. We can lean on the Moya.Response decodable extensions if the AnyDecodable idea works. If not, we may need some protocol like TargetTypeDecodable for users to adopt on their models.

stale[bot] commented 7 years ago

This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

AndrewSB commented 7 years ago

From where I got on my side project with thrift, I realized that something like Moya wasn't useful, and I could use the generated code just as well.

I guess that means Moya can be replaced 😜 I'm switching to gRPC next week to help with some streaming requirements, maybe Moya will have some use there?

@SD10: I could return an AnyDecodable wrapper, but then I'd have to force unwrap types at the callsite, which removes the type safety I was going for. @SD10 can you elaborate re: TargetTypeDecodable?