.package(url: "https://github.com/propellerhr/ios-http-client", .upToNextMajor(from: "1.0.0"))
extension HttpClientConfiguration {
static var myAppDev: HttpClientConfiguration {
HttpClientConfiguration(baseURL: URL(string: "https://jsonplaceholder.typicode.com")!)
}
}
Initialize the HttpClient before using it by executing:
HttpClient.initialize(configuration: .myAppDev)
class ToDoRequest: HttpRequestInterface {
typealias Body = EmptyHttpRequestBody
var path: String = "/todos"
var method: HttpMethod = .get
}
struct ToDo: Codable {
var userId: Int
var title: String
var completed: Bool
}
import RxSwift
let http = HttpClient.shared
let disposeBag = DisposeBag()
func fetchTodos() -> Single<[ToDo]> {
HttpClient.shared.perform(request: ToDoRequest())
}
func yourMethod() {
fetchTodo()
.subscribe(on: ConcurrentDispatchQueueScheduler(qos: .background))
.observe(on: MainScheduler.instance)
.subscribe( { observer in
switch observer {
case .success(let todos):
print("Fetched todos: \(model)")
case .failure(let error):
print("Whoops, something went wrong: \(error)")
}
})
.disposed(by: disposeBag)
}
link |
Stars: 0 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics