Featured iPhone Development Resources Swift

Swift Based Network Abstraction Layer For Simplifying Work With Complex APIs

Earlier this month I mentioned the Swift based networking library AlamoFire created to be AFNetworking reimagined for the conventions of the Swift language.

Here’s a library from Ash Furrow created in Swift called Moya that utilizes AlamoFire providing a network abstraction layer that makes it easier to work with more complex APIs, especially those where an action can lead to different end points.

As the readme states some of the requirements for Moya that were met include:

Treat test stubs as first-class citizens.
Only allow endpoints clearly defined through Moya can be access through Moya, enforced by the compiler.
Allow iterating through all potential API requests at runtime for API sanity checks.
Keep track of inflight requests and don’t support duplicates.

And takes things a step further:

We actually go a bit farther than other network libraries by abstracting the API endpoints away, too. Instead of dealing with endpoints (URLS) directly, we use targets, which represent actions to be taken on the API. This is beneficial if one action can hit different endpoints; for example, if you want to GET a user profile, but the endpoint differs depending on if that user is a friend or not.

You can find Moya on Github here.

An interesting library for those working with complicated web APIs.