Skip to content

An NSURLSession simplification wrapper driven by Swift Protocols

License

Notifications You must be signed in to change notification settings

mix/NaiveHTTP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NaiveHTTP

Work-in-progress at a focused NSURLSession simplification wrapper that is also my learning exercise for Protocol-Oriented Programming.

Installation

This is a framework, so you can either build it as such or include it as a submodule/subproject and link it to your binary in Build Phases.

Don't forget to git submodule update --init to download other dependencies.

Usage

import NaiveHTTP

let sessionConfig = NSURLSessionConfiguration.ephemeralSessionConfiguration()
let naive = NaiveHTTP(configuration: sessionConfig)

let query = ["key1":"value1", "key2":"value2"]
let customHeaders = ["X-Some-Header" : "Feh"]

naive.GET(
    "http://example.org/thing", 
    params: query,
    headers: customHeaders) { (data, response, error) -> Void in
        // Do stuff with the callback values
    }

Convenience functions, like jsonGET let you work with "pure JSON" endpoints.

Protocols

This project is taking on some shape with respect to use of Protocols, which has been helping with testing against fake network responses.

Tests

The main suite runs against http://httpbin.org but is configurable to run against your own local instance of it. Check the NAIVEHTTP_EXTERNAL_TEST_SERVER environment variable under the Test section in the NaiveHTTP scheme and set it to the appropriate value.

If you want to run your own local httpbin you can use Python and PIP:

pip install httpbin
python -m httpbin.core

You can read more info about running a local httpbin at https://github.com/Runscope/httpbin

About

An NSURLSession simplification wrapper driven by Swift Protocols

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.0%
  • Other 2.0%