Skip to content

Guide · Open source

How to use Moya: Swift network layer guide

Updated · written with AI from the project's own documentation and checked against our catalogue data

Moya is an open-source Swift library for making network requests in iOS and macOS apps. Instead of scattering raw URL strings through your code, it lets you describe API endpoints as typed values. This guide explains what Moya is for, what you need before starting, how to get the source, and how to decide whether it fits your project. The README supplied for this listing was empty, so the details below stick to what the project description and topics say.

MoyaMoya/Moya · ★ 15.4k · MIT

Quick start

  1. 1Check prerequisites. Install Xcode, which includes Swift, on a Mac. Confirm your app targets iOS or macOS.
  2. 2Clone the repository. Run git clone https://github.com/Moya/Moya in Terminal to download the source.
  3. 3Open the project. Open the downloaded source in Xcode to read the code and check how it is structured.
  4. 4Define your endpoints. Describe each API endpoint your app uses as a typed value in one place.
  5. 5Check the homepage for setup. Visit https://moya.github.io for current instructions on adding Moya to a project through a package manager.
  6. 6Stub responses in tests. Use the endpoint definitions to stub network responses so your tests do not call live servers.

What Moya does and why it matters

Moya is a network abstraction layer written in Swift. It sits between your app code and the web APIs it calls. You describe each API endpoint as a typed value, so the rest of your code works with those values rather than hand-built URL strings.

According to the project description, this makes requests easier to organize, test, and swap out. Those are the three benefits the source names; the README did not add further detail.

  • Target platforms: iOS and macOS apps.
  • Language: Swift.
  • Licence: MIT.
  • Purpose: organize, test and swap out network requests.

What you need before you start

The source lists two prerequisites: Xcode and Swift. Install Xcode first, since it includes the Swift toolchain used to build iOS and macOS projects.

Moya is a Swift library, so it is only useful in Swift projects. If your project is written in another language, Moya is not the right tool.

  • Xcode
  • Swift
  • An iOS or macOS app that calls web APIs

How to get the Moya source code

The install method listed for this project is a package manager. The README supplied with this listing only provides a command to clone the repository. Run the command below in Terminal to download a local copy of the source.

After cloning, open the code in Xcode to read it or to try it in a project. The source did not specify which package manager commands to use or how to add the library to an app, so check the project's homepage at https://moya.github.io for current setup instructions.

git clone https://github.com/Moya/Moya

How endpoints work in Moya

The core idea is that each endpoint is a typed value. Rather than building a URL string each time you need data, you define the endpoint once and reuse it wherever it is needed. This keeps the list of API calls in one place, which is the main organizational benefit the source describes.

Because requests are described as values, they can be swapped out or replaced in tests. The source notes that Moya is suited to developers who want to stub out network responses in tests, though it does not show the exact code for doing so.

  • Define each endpoint as a typed value.
  • Keep the endpoint definitions together in one place.
  • Reuse the definitions across your app and tests.

Who should use Moya and who should not

Moya is aimed at Swift developers building iOS or macOS apps that call web APIs, especially teams that want network calls organized in one place. It is also a fit for developers who want to write tests that stub network responses.

It is not a good choice if your project only needs a simple one-off request. The abstraction adds setup work that a small project may not need. Non-Swift projects should look elsewhere.

Alternatives to compare with Moya

The project's comparable projects are Alamofire, Apollo iOS and Eureka. Alamofire is a general Swift networking library, Apollo iOS is aimed at GraphQL APIs, and Eureka is a form-building library, so it solves a different problem from Moya.

Before choosing, compare the features you need directly in each project's documentation. The README supplied for Moya was empty, so this guide cannot give a feature-by-feature comparison.

What people use it for

  • Organizing all API endpoints of an iOS app in one set of typed definitions.
  • Writing unit tests that stub out network responses instead of calling a live server.
  • Swapping the underlying network calls without rewriting every place that makes a request.
  • Giving a team a single, shared place to read and change how the app talks to web APIs.

Frequently asked questions

Is Moya free to use?

Yes. Moya is released under the MIT licence, which the project lists on its repository. Check the licence file in the repository for the full terms.

What do I need to install Moya?

The listed prerequisites are Xcode and Swift. The install method is a package manager, and the README supplied only gives a git clone command, so check https://moya.github.io for full setup steps.

Does Moya work with Android or web projects?

No. Moya is written in Swift and is aimed at iOS and macOS apps. Projects in other languages or platforms need a different tool.

What is Moya used for?

Moya is used to make network requests in iOS and macOS apps. It lets you describe API endpoints as typed values, which makes requests easier to organize, test and swap out.

Is Moya a good alternative to Alamofire?

It depends on your needs. Alamofire is a general Swift networking library, while Moya adds a layer that describes endpoints as typed values. The README for Moya was empty, so compare the two in their documentation before deciding.

Why does the Moya README look empty?

The README supplied for this listing was empty, so this guide relies on the repository description and topics. Visit the official homepage at https://moya.github.io for the most complete documentation.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Moya suits Swift developers building iOS or macOS apps that call web APIs, especially teams that want endpoints organized in one place and tests that stub network responses. If you only need a single simple request, or your project is not in Swift, pick a lighter or different tool such as Alamofire. Because the supplied README was empty, check the official homepage before committing to it.

Install options & downloads