This library is a tool for handling different types of HTTP requests in a convenient way.
Emdpoint is a library that provides a convenient way to handle HTTP requests.
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate Emdpoint
into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/GSM-MSG/Emdpoint.git", .upToNextMajor(from: "1.0.0"))
]
If you prefer not to use either of the aforementioned dependency managers, you can integrate MSGLayout into your project manually.
import Emdpoint
enum JsonEndpoint {
case todos
}
extension JsonEndpoint: EndpointType {
var baseURL: URL {
URL(string: "https://jsonplaceholder.typicode.com/")!
}
var route: Route {
.get("todos")
}
var task: HTTPTask {
.requestPlain
}
}
import Combine
import UIKit
final class ViewController: UIViewController {
var bag = Set<AnyCancellable>()
override func viewDidLoad() {
super.viewDidLoad()
let client = EmdpointClient<TestEndpoint>()
// MARK: - Async/Await
Task {
let data = try await client.request(.todos).data
let prettyData = try? JSONSerialization.jsonObject(with: data)
print(prettyData)
}
// MARK: - Combine
client.requestPublisher(.todos)
.sink { completion in
switch completion {
case .finished:
print("finished")
case .failure(let error):
print(error)
}
} receiveValue: { data in
print(data)
}
.store(in: &bag)
// MARK: - Completion Closure
client.request(.todos) { result in
switch result {
case .success(let data):
print(data)
case .failure(let error):
print(error)
}
}
}
}
link |
Stars: 2 |
Last commit: 6 weeks ago |
Full Changelog: https://github.com/GSM-MSG/Emdpoint/compare/3.4.0...3.5.0
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics