To install, check out Get Started tab on cocoapods.org.
To use HTTPLite in your project add the pod below to your project's Podfile
pod 'HTTPLite'
Then, from the command line, run:
$ pod install # or pod updateThen you are good to start using it 👍
To use the library, import it in your file.
import HTTPLiteFollow that with a simple declaration of a Request object with the recipient URL.
guard let request = Request(Url: "https://www.google.com") else {
print("Can't intialize the request")
return
}After that, we can perform any HTTP verb.
let params: [String: String] = ["Artist" : "Michael Jackson", "Album" : "Thriller"]
request.get(parameters: params, success: { response in
if let data = response.data {
}
if let url = response.url {
}
}, failure: { error in
}) { progress in
}let params: [String: String] = ["album" : "Michael Jackson - Thriller"]
request.get(parameters: params, success: { response in
if let data = response.data {
do {
let JSON = try JSONSerialization.jsonObject(with: data,
options: .mutableContainers)
} catch let error {
}
if let url = response.url { }
}, failure: { error in
}, progress: { progress in
})let params: [String: String] = ["healer":"Grigori Yefimovich Rasputin", "powers": "healer and adviser"]
request.post(parameters: params, success: { response in
print("response data:\(response)")
}, failure: { error in
}, progress: { progress in
})We can download files using either download() or get().
let params: [String: String] = ["image":"to be downloaded as data"]
request.get(parameters: params, success: { response in
if let data = response.data {
let image = UIImage(data: data)
}
if let url = response.url { }
}, failure: { error in
}, progress: { progress in
})let params: [String: String] = ["image":"to be downloaded as one file"]
request.download(parameters: params, success: { response in
if let data = response.data { }
if let url = response.url {
let image = UIImage(contentsOfFile: url.path)
}
}, failure: { error in
}, progress: { progress in
})We can easily measure the progress of a file download using the progress closure.
let params: [String: String] = ["image":"to be downloaded as one file with progress"]
request.download(parameters: params, success: { response in
if let data = response.data { }
if let url = response.url {
let image = UIImage(contentsOfFile: url.path)
}
}, failure: { error in
}, progress: { progress in
print("Download progress \(progress)")
})If you encounter a problem, please open a new issue. Also, pull requests are always welcome!

