Simple HTTP Networking Library with Async/Await and Codable.
let todos: [Todo] = try await FakeAPI.todos.request()
To integrate Resty into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'Resty'
Then, run the following command:
$ pod install
To use SwiftyContacts as a Swift Package Manager package just add the following in your Package.swift file.
dependencies: [
.package(url: "https://github.com/satishbabariya/Resty.git", .upToNextMajor(from: "1.0.0"))
]
Import SwiftyContacts into your porject
import Resty
let todos: [Todo] = try await FakeAPI.todos.request()
FakeAPI.todos.request(type: [Todo].self) { result in
switch result {
case let .success(todos):
// Array of [Todo]
case let .failure(error):
// error
}
}
struct Todo: Codable {
let id: Int
let title: String
let completed: Bool
}
enum FakeAPI: Resty {
case todos
}
extension FakeAPI {
var host: String {
return "https://jsonplaceholder.typicode.com/"
}
var path: String {
return ""
}
var endpoint: String {
switch self {
case .todos:
return "todos"
}
}
var method: HTTPMethod {
switch self {
case .todos:
return .get
}
}
var parameters: [String: Any]? {
return nil
}
var headers: [String: String]? {
return nil
}
}
Satish Babariya, [email protected]
Resty is available under the MIT license. See the LICENSE file for more info.