Taking Moya to the Next Level
Moya is an extremely versatile networking library with too many additional features to fully cover in this tutorial, but they are definitely worth mentioning:
-
Reactive Extensions: Moya provides and maintains two excellent reactive additions to Moya for RxSwift and ReactiveSwift, aptly named RxMoya and ReactiveMoya.
-
Plugins: Moya lets you create pieces named Plugins, which you can use to modify requests and responses, or to perform side effects. The can be useful, for example, for logging requests and responses or automatically showing a network activity indicator when running network requests.
-
Testing: As mentioned earlier, every
TargetType
has a sampleData
property wherein you can provide a stubbed response for your endpoints. When creating a MoyaProvider
, you can provide a stubClosure
, which defines if you want Moya to return a stubbed response or a real one (the default). You can learn much more about this in Moya’s testing documentation.
-
Harvey: Speaking of stubbing responses — some of the team behind Moya are developing a separate framework named Harvey for easy mocking of network responses. It is still in early development but I’d highly recommend following this project.
Moya is a feature-packed networing library
![Moya is a feature-packed networing library](https://koenig-media.raywenderlich.com/uploads/2018/04/moyafeatures-1.jpg)
Moya is a feature-packed networing library
Where to Go From Here?
You can download the completed version of the project using the Download Materials button at the top or bottom of this tutorial. Don’t forget to set your Imgur Client ID and Marvel public and private keys in the project!
In this tutorial, you’ve learned the basics of using Moya and then some! You have everything you need to take your networking layer to the next level.
The best place to continue your exploration of Moya would be its official documentation page, which is very informative and dives into much more detail on every aspect of Moya, and even has a maintained Chinese translation.
In the meantime, if you have any questions or comments about this tutorial or networking in general, please join the forum discussion below.