Moya Tutorial for iOS: Getting Started

Moya is a networking library inspired by the concept of encapsulating network requests in type-safe way, typically using enumerations, that provides confidence when working with your network layer. Become a networking superhero with Moya! By Shai Mishali.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

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:

  1. Reactive Extensions: Moya provides and maintains two excellent reactive additions to Moya for RxSwift and ReactiveSwift, aptly named RxMoya and ReactiveMoya.
  2. 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.
  3. 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.
  4. 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

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.