Merchant is a type-safe HTTP client for iOS, iPadOS, macOS, watchOS and tvOS. Inspired by https://github.com/square/retrofit.

it allows you to simply "property wrap" any codable Swift struct and Merchant will do all the heavy lifting of initiating the HTTP request and decoding the HTTP response data into your model all in a type safe and declarative way.

Installation

CocoaPods

Merchant is available through CocoaPods. To install
it, simply add the following line to your Podfilet

pod 'Merchant'

Swift Package Manager

Merchant is available through Swift Package Manager. To install
it, simply add the following to your Package.swift file.

You can learn more on many other ways to customize the Alamofire session object here

Lastly you can specify a global url query, like an API key for example:

builder.query(["api_key": "KEY_HERE"])

Declare your HTTP Requests

Create your HTTP API client in a declarative way 😌 and wrap your each your properties with one of @GET, @POST, PUT, @DELETE, @PATCH or @DELETE property wrappers depending on the HTTP request you want to make.

The type of the wrapped property should be a decodable struct/class that represents that particular HTTP JSON response.

For example we would declare a GET request to this url http://api.openweathermap.org/data/2.5/weather like so:

You can specify a dynamically generated URL that depends on some variable.

For example lets say that you want to specify a URL to delete any user given their id, you could declare it like the below snippet and you will then be able to "inject" the actual value of user_id when you are making the request.

...
@DELETE(path="/users/{user_id}")
var deleteUser: Bool
...

Lastly lets make the requests.

Create an instance of the above declared ApplicationClient class and call the desired property like so: