Lightweight lib around NSURLSession to ease HTTP calls

Overview

AeroGear iOS HTTP

Maintenance circle-ci License GitHub release CocoaPods Platform

Thin layer to take care of your http requests working with NSURLSession.

Project Info
License: Apache License, Version 2.0
Build: CocoaPods
Languague: Swift 4
Documentation: http://aerogear.org/ios/
Issue tracker: https://issues.jboss.org/browse/AGIOS
Mailing lists: aerogear-users (subscribe)
aerogear-dev (subscribe)

Features

  • Json serializer
  • Multipart upload
  • HTTP Basic/Digest authentication support
  • Pluggable object serialization
  • background processing support

Installation

CocoaPods

In your Podfile add:

pod 'AeroGearHttp'

and then:

pod install

to install your dependencies

Usage

Request

To perform an HTTP request use the convenient methods found in the Http object. Here is an example usage:

let http = Http(baseURL: "http://server.com")

http.request(method: .get, path: "/get", completionHandler: {(response, error) in
     // handle response
})

http.request(method: .post, path: "/post",  parameters: ["key": "value"],
                    completionHandler: {(response, error) in
     // handle response
})
...

Authentication

The library also leverages the build-in foundation support for http/digest authentication and exposes a convenient interface by allowing the credential object to be passed on the request. Here is an example:

NOTE: It is advised that HTTPS should be used when performing authentication of this type

let credential = URLCredential(user: "john",
                                 password: "pass",
                                 persistence: .none)

http.request(method: .get, path: "/protected/endpoint", credential: credential,
                                completionHandler: {(response, error) in
   // handle response
})

You can also set a credential per protection space, so it's automatically picked up once http challenge is requested by the server, thus omitting the need to pass the credential on each request. In this case, you must initialize the Http object with a custom session configuration object, that has its credentials storage initialized with your credentials:

// create a protection space
let protectionSpace = URLProtectionSpace(host: "httpbin.org",
                        port: 443,
                        protocol: NSURLProtectionSpaceHTTP,
                        realm: "[email protected]",
                        authenticationMethod: NSURLAuthenticationMethodHTTPDigest)

// setup credential
// notice that we use '.ForSession' type otherwise credential storage will discard and
// won't save it when doing 'credentialStorage.setDefaultCredential' later on
let credential = URLCredential(user: "user",
                        password: "password",
                        persistence: .forSession)
// assign it to credential storage
let credentialStorage = URLCredentialStorage.shared
credentialStorage.setDefaultCredential(credential, for: protectionSpace);

// set up default configuration and assign credential storage
let configuration = URLSessionConfiguration.default
configuration.urlCredentialStorage = credentialStorage

// assign custom configuration to Http
let http = Http(baseURL: "http://httpbin.org", sessionConfig: configuration)
http.request(method: .get, path: "/protected/endpoint", completionHandler: {(response, error) in
    // handle response
})

OAuth2 Protocol Support

To support the OAuth2 protocol, we have created a separate library aerogear-ios-oauth2 that can be easily integrated, in order to provide out-of-the-box support for communicating with OAuth2 protected endpoints. Please have a look at the "Http and OAuth2Module" section on our documentation page for more information.

Documentation

For more details about that please consult our documentation.

Demo apps

Take a look in our demo apps:

Development

If you would like to help develop AeroGear you can join our developer's mailing list, join #aerogear on Freenode, or shout at us on Twitter @aerogears.

Also takes some time and skim the contributor guide

Questions?

Join our user mailing list for any questions or help! We really hope you enjoy app development with AeroGear!

Found a bug?

If you found a bug please create a ticket for us on Jira with some steps to reproduce it.

Comments
  • added basic/digest support option

    added basic/digest support option

    done for AGIOS-255

    the functionality is exercised in the HttpAuthenticationTests test case class where the different http/digest options are executed plus a test case with where a protection space is used and assigned to the NSURLSession.defaultConfiguration() (without the need to pass any credential object)

    besides the tests, a demo app exerting basic/digest has also been created to demonstrate and can be found here

    opened by cvasilak 9
  • Convert AeroGearHttp Test scheme to Integration Tests scheme

    Convert AeroGearHttp Test scheme to Integration Tests scheme

    this PR adds an 'IntegrationTests' target that enables tests to be run within the context of the emulator. Details of why this was required can be found on our JIRA AGIOS-330

    To test: After running pod install and opening the workspace, choose IntegrationTest schema, and then choose Product->Test. Tests should run and succeed.

    @corinnekrych @danbev mind to have a look?

    opened by cvasilak 6
  • revisit http to git oauth2 module

    revisit http to git oauth2 module

    • be able to modify URL after having created Http object
    • inject headers for oauth2 token
    • string response serializer required by facebook OAuth2 provider
    opened by corinnekrych 4
  • Linking http-stubs to AeroGearTests build phase.

    Linking http-stubs to AeroGearTests build phase.

    To test:

    1. First clean out you build folder in Xcode using CTRL+SHIFT+OPTION+CMD
    2. rm -rf AeroGearHttpTests/aerogear-ios-httpstub/
    3. git submodule init && git submodule update
    4. In Xcode now run the test using CMD+U
    opened by danbev 4
  • Added Support for File Uploads With Responses

    Added Support for File Uploads With Responses

    Currently it is impossible to get a response from a file upload. This allows someone to specify a response serializer like:

    http.upload(method, data: data, responseSerializer: JsonResponseSerializer(), progress: { (b, writtenBytes, totalBytes) -> Void in
    
    }, completionHandler: { (response, error) -> Void in
    
    })
    
    opened by k3zi 3
  • Agios 428.ios 8.3.migration

    Agios 428.ios 8.3.migration

    This is the changes required for iOS 8.3 Do not merge yet as Travis is not ready. Let's wait for next week announcement: http://blog.travis-ci.com/2015-04-09-this-week-in-travis-ci/

    opened by corinnekrych 2
  • switch to XCTAssertTrue assertion

    switch to XCTAssertTrue assertion

    switching to XCTAssertTrue assertion when comparing solve the test failure. Seems to be some buggy optimisation that causes test case to fail if XCTAssertEqual is used. In the following code, testExample1 succeeds and testExample2 fails although they are identical code.

    My search on the net haven't revealed something concrete reasoning apart from some suggestions to switch to XCTAssertTrue [1].

    func testExample1() {
        XCTAssertEqual("foobar", "foobar")
    }
    func testExample2() {
        XCTAssertEqual("foobar", "foobar")
    }
    

    [1] http://www.raywenderlich.com/forums/viewtopic.php?f=37&t=9475

    opened by cvasilak 2
  • pass response data to completionHandler even upon error

    pass response data to completionHandler even upon error

    Upon server error some information about error itself may come in data field of response. This change passes this data even upon error! In this case the client code can check for error in this way:

    http.POST("login", parameters: params, completionHandler: {(response, error) in 
        if(error != nil) {
            println(response) // print response data that may describe the error.
        }
    })
    
    opened by brunomacf 2
Releases(2.0.0)
Owner
AeroGear
Modern App Dev begins here - RealTime GraphQL and Push
AeroGear
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support

Networking was born out of the necessity of having a simple networking library that doesn't have crazy programming abstractions or uses the latest rea

Nes 1.3k Dec 17, 2022
NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. ⚙️🚀

SONetworking NSURLSession network abstraction layer, using Codable and Decodable for response and Encodable for request. Project Folder and File Struc

Ahmad AlSofi 4 Jan 28, 2022
A modern download manager based on NSURLSession to deal with asynchronous downloading, management and persistence of multiple files.

TWRDownloadManager TWRDownloadManager A modern download manager for iOS (Objective C) based on NSURLSession to deal with asynchronous downloading, man

Michelangelo Chasseur 407 Nov 19, 2022
Http - Demo for Http Layer

http Example To run the example project, clone the repo, and run pod install fro

null 0 Jan 24, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
📡 RealHTTP is a lightweight yet powerful client-side HTTP library.

RealHTTP RealHTTP is a lightweight yet powerful client-side HTTP library. Our goal is make an easy to use and effortless http client for Swift. Featur

Immobiliare Labs 233 Jan 7, 2023
Lightweight, flexible HTTP server framework written in Swift

Hummingbird Lightweight, flexible server framework written in Swift. Hummingbird consists of three main components, the core HTTP server, a minimal we

Hummingbird 245 Dec 30, 2022
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
FlyingFox - a lightweight HTTP server built using Swift Concurrency

Usage Credits Introduction FlyingFox is a lightweight HTTP server built using Swift Concurrency. The server uses non blocking BSD sockets, handling ea

Simon Whitty 262 Dec 24, 2022
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity

RxSwift Community 69 Jul 5, 2022
A glorious Swift wrapper around NSNotificationCenter

Kugel A glorious Swift wrapper around NSNotificationCenter. ⚠️ Deprecated ⚠️ This library is deprecated and will not be maintained anymore. With Swift

Scoop 75 Sep 22, 2022
A Combine-style wrapper around Network's NWConnection with a UDP protocol

A Combine-style wrapper around Network's NWConnection with a UDP protocol

Emlyn Bolton 3 Sep 26, 2022
Elegant HTTP Networking in Swift

Alamofire is an HTTP networking library written in Swift. Features Component Libraries Requirements Migration Guides Communication Installation Usage

Alamofire 38.7k Jan 8, 2023
Swift HTTP for Humans

Just is a client-side HTTP library inspired by python-requests - HTTP for Humans. Features Just lets you to the following effortlessly: URL queries cu

Daniel Duan 1.4k Dec 30, 2022
Versatile HTTP Networking in Swift

Net is a versatile HTTP networking library written in Swift. ?? Features URL / JSON / Property List Parameter Encoding Upload File / Data / Stream / M

Intelygenz 124 Dec 6, 2022
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022
Swift/Obj-C HTTP framework with a focus on REST and JSON

Now Archived and Forked PMHTTP will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork of PHMT

Postmates Inc. 509 Sep 4, 2022
This package is meant to make http request of an easy way inspiren in the architecture of Moya package

NetworkAgent This package is meant to make http request of an easy way inspiren in the architecture of Moya package. This package is 100% free of depe

Angel Rada 19 Sep 8, 2022