Zen is simple yet powerfull Networking library for iOS. It leverage the powerfull feature of Alamofire and Swift to make building Network Layer more straight forward and efficient.
- Xcode 11.3+
- Swift 5.1+
- iOS 13+
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Zen into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'Zen', '~> 0.1.7'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Zen into your Xcode project using Carthage, specify it in your Cartfile
:
github "KarimEbrahemAbdelaziz/Zen" ~> 0.1.7
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but Zen does support its use on supported platforms.
Once you have your Swift package set up, adding Zen as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/KarimEbrahemAbdelaziz/Zen.git", .upToNextMajor(from: "0.1.7"))
]
struct Todo: Codable {
var userId: Int
var id: Int
var title: String
var completed: Bool
}
import Zen
class APIClient {
@ZenRequest<Todo>("https://jsonplaceholder.typicode.com/todos/")
static var fetchTodo: Service<Todo>
}
try? APIClient.$fetchTodo
// Specifiy HTTPMethod for The Request
.set(method: .get)
// Specifiy Custom PATH for The Request
.set(path: "1")
// Build the Request
.build()
APIClient.fetchTodo { result in
switch result {
case .success(let todo):
print(todo.title)
case .failure(let error):
print(error)
}
}
try? APIClient.$fetchUsers
// Specifiy HTTPMethod for The Request
.set(method: .get)
// Specifiy Query Parameters for The Request
.set(parameters: .url([
"delay": "3"
]))
// Build the Request
.build()
APIClient.fetchUsers { result in
switch result {
case .success(let users):
print(users.data.count)
case .failure(let error):
print(error)
}
}
try? APIClient.$createUser
// Specifiy HTTPMethod for The Request
.set(method: .post)
// Specifiy Body Parameters for The Request
.set(parameters: .body([
"name": "Karim Ebrahem",
"job": "iOS Software Engineer"
]))
// Build the Request
.build()
APIClient.createUser { result in
switch result {
case .success(let user):
print(user.name)
case .failure(let error):
print(error)
}
}
- Support all HTTP Methods Requests.
- Support Body Parameters.
- Support Query Parameters.
- Support Headers.
- Support Interceptors.
Karim Ebrahem, [email protected] You can find me on Twitter @k_ebrahem_.
Zen is available under the MIT license. See the LICENSE
file for more info.
Zen will be updated when necessary and fixes will be done as soon as discovered to keep it up to date.
Enjoy!