Git Product home page Git Product logo

restofire's Introduction

Restofire: A Protocol Oriented Networking Abstraction Layer in Swift

Restofire

Platforms License

Swift Package Manager Carthage compatible CocoaPods compatible

Travis

Join the chat at https://gitter.im/Restofire/Restofire

Restofire is a protocol oriented networking abstraction layer in swift that is built on top of Alamofire to use services in a declartive way.

Features

  • No Learning Curve
  • Default Configuration for Base URL / headers / parameters etc
  • Multiple Configurations
  • Single Request Configuration
  • Custom Response Serializer
  • Authentication
  • Response Validations
  • Request NSOperation
  • RequestEventuallyOperation with Auto Retry
  • Complete Documentation
  • Tutorial

Requirements

  • iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 7.3+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 0.39.0+ is required to build Restofire 1.1.0+.

To integrate Restofire into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Restofire', '~> 1.1'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Restofire into your Xcode project using Carthage, specify it in your Cartfile:

github "RahulKatariya/Restofire" ~> 1.1

Swift Package Manager

To use Restofire as a Swift Package Manager package just add the following in your Package.swift file.

import PackageDescription

let package = Package(
    name: "HelloRestofire",
    dependencies: [
        .Package(url: "https://github.com/Restofire/Restofire.git", versions: Version(1, 1, 0)..<Version(1, 2, 0))
    ]
)

Usage

Configuring Restofire

import Restofire

class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        Restofire.defaultConfiguration.baseURL = "http://www.mocky.io/v2/"
        Restofire.defaultConfiguration.headers = ["Content-Type": "application/json"]
        Restofire.defaultConfiguration.logging = true
        Restofire.defaultConfiguration.authentication.credential = NSURLCredential(user: "user", password: "password", persistence: .ForSession)
        Restofire.defaultConfiguration.validation.acceptableStatusCodes = [200..<300]
        Restofire.defaultConfiguration.validation.acceptableContentTypes = ["application/json"]
        Restofire.defaultConfiguration.retry.retryErrorCodes = [NSURLErrorTimedOut,NSURLErrorNetworkConnectionLost]
        Restofire.defaultConfiguration.retry.retryInterval = 20
        Restofire.defaultConfiguration.retry.maxRetryAttempts = 10
        let sessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
        sessionConfiguration.timeoutIntervalForRequest = 7
        sessionConfiguration.timeoutIntervalForResource = 7
        sessionConfiguration.HTTPAdditionalHeaders = Manager.defaultHTTPHeaders
        Restofire.defaultConfiguration.manager = Alamofire.Manager(configuration: sessionConfiguration)

        return true
  }

}

Creating a Service

import Restofire

class PersonGETService: Requestable {

    typealias Model = [String: AnyObject]
    var path: String = "56c2cc70120000c12673f1b5"

}

Consuming the Service

import Restofire

class ViewController: UIViewController {

    var person: [String: AnyObject]!
    var requestOp: RequestOperation<PersonGETService>!

    func getPerson() {
        requestOp = PersonGETService().executeTask() {
            if let value = $0.result.value {
                person = value
            }
        }
    }

    deinit {
        requestOp.cancel()
    }

}

Examples

License

Restofire is released under the MIT license. See LICENSE for details.

restofire's People

Contributors

rahul0x24 avatar gitter-badger avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

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.