Elegant Networking in Swift. But more Swift.
Sora is an declarative Alamofire wrapper.
| Platform | Minimum Swift Version | Installation |
|---|---|---|
| iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ | 5.5 | Swift Package Manager |
File->Add Packages...And paste the repository URL.- Or add it to the
dependenciesvalue of yourPackage.swift.
dependencies: [
.package(url: "https://github.com/Mercen-Lee/Sora.git", .branch("main"))
]struct Sample: Service {
let endpoint: URL = .init(string: "https://sample.com/api/")!
let interceptor: Interceptor = .init()
let path: [String]
}struct GetUserRequest: Requestable {
let route = Sample.path("user")
let method: RequestMethod = .get
}
AF.request(GetUserRequest())struct PostUserRequest: Requestable, Body {
let route = Sample.path("user", "post")
let method: RequestMethod = .post
let body: Body
struct Body: Encodable {
let id: Int
let name: String
}
}
AF.request(PostUserRequest(body: .init(id: 1, name: "mercen")))do {
let response = try await GetUserRequest()
.request(with: AnyDecodable.self)
} catch let error {
// on Error
}