Pure Swift cURL Requests.
Inspired on Python Requests.
A beautiful HTTP Client for your Swift projects.
Add this project on your Package.swift
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/vsouza/wings.git", majorVersion: 0, minor: 0)
]
)
import Wings
let w = Wings()
if let response = w.get(url:"http://localhost:8080/", headers:nil){
print(response) \\ Response() struct type
print(response.headers) \\ list of headers [AnyHashable : Any]?
print(response.statusCode) \\ (Int?)
print(response.json) \\ json response ([String: Any]?)
print(response.text) \\ text response (String?)
}
import Wings
var headers: [String: String] = ["Content-Type": "application/json"]
var body : [String: Any] = ["owner": "vsouza"]
let jsonBody = try? JSONSerialization.data(withJSONObject: body)
let w = Wings()
if let response = w.post(url: "http://localhost:8080/", headers: headers, body:jsonBody) {
if let json = response.json{
print(json["owner"]) // vsouza
}
}
- 0.0.1
- Work in progress
Vinicius Souza – @iamvsouza – hi@vsouza.com
Distributed under the MIT license. See License