CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

SwiftRequest 0.0.4

SwiftRequest 0.0.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2015
SPMSupports SPM

Maintained by Ricky Robinett.



SwiftRequest is a simple HTTP client for Swift. It was inspired by the Node.js Request library and Python Requests.

var swiftRequest = SwiftRequest()

swiftRequest.get("https://en.wikipedia.org/wiki/Brooklyn", callback: {err, response, body in
  if( err == nil ) {
    println(body)
  }
})

Installation

Manual

Drop the SwiftRequest folder into your Xcode project.

Getting Started

GET Requests

Simple GET Request

var swiftRequest = SwiftRequest()

swiftRequest.get("http://news.ycombinator.com", callback: {err, response, body in
  if( err == nil ) { 
    println(body)
  }
})

GET Request with Parameters

swiftRequest.get("http://pokeapi.co/api/v1/pokemon/", params: ["limit":"5"], callback: {err, response, body in
  if( err == nil ) {
    println(body)
  }
})

GET Request with Authentication

swiftRequest.get("https://api.github.com/user", auth: ["username" : "user", "password" : "pass"],callback: {err, response, body in
    if( err == nil ) {
        println(body)
    }
})

POST Requests

var swiftRequest = SwiftRequest()

var data = [
    "Name" : "Ricky",
    "Favorite Band" : "Refused",
    "Age" : "29"
]

swiftRequest.post("http://requestb.in/ukfc8euk", data: data, callback: {err, response, body in
  if( err == nil ) {
    println(body)
  }
})

Sample GET image

var swiftRequest = SwiftRequest()

swiftRequest.get("http://graphics8.nytimes.com/images/2013/02/22/nyregion/KENTILE-01/KENTILE-01-articleLarge.jpg", {err, response, body in
  println(body)
  var image = UIImage(data: body as NSData)
  self.imageView.image = image
})