Coder Social home page Coder Social logo

aerogear-ios-http's Introduction

aerogear-ios-http Build Status

This module currently build with Xcode 8 and supports iOS8, iOS9, iOS10.

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

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

100% Swift 3.0.

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

Example Usage

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 communicated with OAuth2 protected endpoints. Please have a look at the "Http and OAuth2Module" section on our documentation page for more information.

Do you want to try it on your end? Follow next section steps.

Build, test and play with aerogear-ios-http

  1. Clone this project

  2. Get the dependencies

The project uses OHHTTPStubs framework for stubbing its http network requests and utilizes CocoaPods release for handling its dependencies. As a pre-requisite, install CocoaPods and then install the pod. On the root directory of the project run:

pod install
  1. open AeroGearHttp.xcworkspace

Adding the library to your project

To add the library in your project, you can either use CocoaPods or manual install in your project. See the respective sections below for instructions:

Using CocoaPods

We recommend you useCocoaPods-1.1.1 release or greater.

In your Podfile add:

pod 'AeroGearHttp'

and then:

pod install

to install your dependencies

Documentation

For more details about the current release, please consult our documentation.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.