let todos: [Todo] = try await FakeAPI.todos.request()
Request with codable
FakeAPI.todos.request(type: [Todo].self) { result in
switch result {
case let .success(todos):
// Array of [Todo]
case let .failure(error):
// error
}
}
REST API Setup
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
}
}
resty
Simple HTTP Networking Library with Async/Await and Codable.
Installation
CocoaPods
To integrate Resty into your Xcode project using CocoaPods, specify it in your
Podfile
:Then, run the following command:
Swift Package Manager
To use SwiftyContacts as a Swift Package Manager package just add the following in your Package.swift file.
Get started
Import SwiftyContacts into your porject
Request with codable async/await
Request with codable
REST API Setup
Author
Satish Babariya, satish.babariya@gmail.com
License
Resty is available under the MIT license. See the LICENSE file for more info.