vsouza / Wings

Pure Swift cURL Requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wings

Pure Swift cURL Requests.

Swift Version Build Status License codebeat-badge

Inspired on Python Requests.

A beautiful HTTP Client for your Swift projects.

Installation

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)
    ]
)

Usage example

GET

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?)

}

POST JSON

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
    }
}

Release History

  • 0.0.1
    • Work in progress

Meta

Vinicius Souza – @iamvsouzahi@vsouza.com

Distributed under the MIT license. See License

https://github.com/vsouza

About

Pure Swift cURL Requests

License:MIT License


Languages

Language:Swift 65.5%Language:Shell 31.4%Language:Makefile 3.1%