Hermes is a swift package that wraps around apple's native URLSession to organize your APIs.
Use the swift package manager (https://github.com/josephjoeljo/Hermes) to add to your project.
Hermes uses a class called Courrier
to help organize your API callS.
import Hermes
let service = Courrier(.HTTP, host:"your-host")
import Hermes
let service = Courrier(.HTTP, host:"localhost:80")
// your queries
let queries = [
URLQueryItem(name: "name", value: "value"),
]
// your endpoint
let endpoint = Endpoint("/path", queries)
// making the request
try {
let (data, response) = try await service.Request(.GET, endpoint)
} catch (error) {
// handle error
}
// your endpoint
let endpoint = Endpoint("/path")
// your post data
let data = Data()
// making the request
try {
let (data, response) = try await service.Request(.POST, endpoint, body: data)
} catch(error) {
// handle error
}
let dict = [
"Connection": "keep-alive"
]
// your endpoint
let endpoint = Endpoint("/path")
// making the request
try {
let (data, response) = try await service.Request(.POST, endpoint, body: data, headers: dict)
} catch(error) {
// handle error
}
Force cast down the error thrown as a Network Error And print the localized Description to see its contents
let newError = error as! NetworkError
print(newError.localizedDescription)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.