Cria
Meet
🏵 Introduction
Cria is an elegant HTTP requests framework for Swift with
Note
|
Cria means a juvenile alpaca, also commonly known as 草泥马 in Mandarin Chinese.
|
📋 Requirements
Type | Requirement | |
---|---|---|
Platform |
iOS |
8.0 |
macOS |
10.10 |
|
tvOS |
9.0 |
|
watchOS |
N/A |
|
Linux |
N/A |
|
IDE |
Xcode |
10.2 |
Language |
Swift |
5 |
📲 Installation
Manually
Copy all files in the Cria
directory into your project.
❤️ Contribution
You are welcome to fork and submit pull requests.
🔖 License
Cria
is open-sourced software, licensed under the MIT
license.
🔫 Usage
import Cria
import Oath
let cria = Cria.init("https://meniny.cn/api/v2/")
// A simple get request:
cria.get("posts.json").then { response in
print("Done: ", response.code)
}.onError { error in
print("Error: ", error.localizedDescription)
}
// or:
cria.do(.get, path: "posts.json").then { response in
print("Done: ", response.code)
}.onError { error in
print("Error: ", error.localizedDescription)
}
For multipart-form
:
import Cria
import Oath
let cria = Cria.init("https://some-domain.com/")
let image = #imageLiteral(resourceName: "Cria")
if let data = UIImageJPEGRepresentation(image, 1) {
let part = CriaFormPart.init(.data(data), name: "image", mimetype: "image/jpeg")
cria.postMultipart("some_uploading_api/subpath/", data: [part]).progress { p in
print("Progress: ", p)
}.then { response in
print("Done: ", response.code)
}.onError { error in
print("Error: ", error.localizedDescription)
}
}