GithubHelp home page GithubHelp logo

hajjboy95 / fire-in-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meniny/fire

0.0 2.0 0.0 313 KB

A delightful HTTP/HTTPS networking framework for iOS/macOS/watchOS/tvOS platforms written in Swift.

License: MIT License

Swift 60.62% Ruby 1.61% Objective-C 5.93% Shell 31.84%

fire-in-swift's Introduction

Fire
Version Author Build Passing Swift
Platforms MIT
Cocoapods Carthage SPM


Introduction

What's this?

Fire is a delightful HTTP/HTTPS networking framework for iOS/macOS/watchOS/tvOS platform written in Swift and inspired by Python-Requests: HTTP for Humans.

Fire was written for humans to read, and incidentally, for machines to execute :)

Features

  • Chainable Request / Response Methods
  • Upload File / Data / MultipartFormData
  • HTTP Basic Authorization
  • TLS Certificate and Public Key Pinning
  • Comprehensive Unit and Integration Test Coverage
  • Synchronously/Asynchronously Request
  • Timeouts
  • form (x-www-form-encoded)/JSON HTTP body

Requirements

  • iOS 8.0+
  • macOS 10.10+
  • watchOS 2.0+
  • tvOS 9.0+
  • Xcode 8 with Swift 3

Dependency

Installation

CocoaPods

pod 'Fire'

Contribution

You are welcome to fork and submit pull requests.

License

Fire is open-sourced software, licensed under the MIT license.

Usage

To send a request with Fire, you need to do 3 steps.

First, build up a Fire object:

let f = Fire.build(HTTPMethod: .GET, url: "https://yourdomain.com/get?l=zh")

Then, config the Fire object:

f.setParams(["key": "value"])
f.setFiles([file])
f.setHTTPHeaders(["Accept": "application/json"])
f.setBasicAuth("user", password: "pwd!@#")
f.setHTTPBody(raw: json.rawValue)
let certData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("FireDemo", ofType: "cer")!)!
f.setSSLPinning(localCertData: certData) {
    print("Warning: Under Man-in-the-middle attack!!")
}
f.onError({ (error) -> Void in
    print("Error: Network offline!")
})

Finally, fire up:

f.fire { (json, resp) -> Void in
    print(json["arg"]["key"].stringValue)
}

// or

f.fireForJSON { (json, resp) -> Void in
    print(json["arg"]["key"].stringValue)
}

// or

f.fireForString { (str, resp) -> Void in
    print(str)
}

// or

f.fireForData { (data, resp) -> Void in
    print("Success")
}

If you want to cancel it:

f.cancel {
   print("Canceled")
}

Use FireDispatch if you want to send requests synchronously:

let f = Fire.build(HTTPMethod: .GET, url: api.stringValue, timeout: timeout, dispatch: dispatch)

中文介绍

这是什么?

Fire 一个使用 Swift 书写的轻量级 iOS/macOS/watchOS/tvOS 平台 HTTP/HTTPS 网络框架,深受 Python-Requests: HTTP for Humans 启发。

Fire 为了更好的可读性而生,碰巧还可以运行 :)

特性

  • 链式调用的请求和响应方法
  • 上传文件和数据
  • 支持 HTTP Basic 认证
  • 支持 SSL Pinning
  • 全面的单元和集成测试覆盖
  • 同步/异步请求
  • 超时
  • 支持 form (x-www-form-encoded)/JSON HTTP 请求体

环境

  • iOS 8.0+
  • macOS 10.10+
  • watchOS 2.0+
  • tvOS 9.0+
  • Xcode 8 及 Swift 3

依赖

安装

CocoaPods

pod 'Fire'

贡献

欢迎任何人提交代码和问题。

协议

Fire 是一个开源软体,遵循 MIT 协议。

使用

要使用 Fire 发送请求,你只需要三个步骤。

首先,构建一个 Fire 实例:

let f = Fire.build(HTTPMethod: .GET, url: "https://yourdomain.com/get?l=zh")

然后,进行一些配置:

f.setParams(["key": "value"])
f.setFiles([file])
f.setHTTPHeaders(["Accept": "application/json"])
f.setBasicAuth("user", password: "pwd!@#")
f.setHTTPBody(raw: json.rawValue)
let certData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("FireDemo", ofType: "cer")!)!
f.setSSLPinning(localCertData: certData) {
    print("Warning: Under Man-in-the-middle attack!!")
}
f.onError({ (error) -> Void in
    print("Error: Network offline!")
})

最后,发起请求:

f.fire { (json, resp) -> Void in
    print(json["arg"]["key"].stringValue)
}

// or

f.fireForJSON { (json, resp) -> Void in
    print(json["arg"]["key"].stringValue)
}

// or

f.fireForString { (str, resp) -> Void in
    print(str)
}

// or

f.fireForData { (data, resp) -> Void in
    print("Success")
}

如果你需要取消请求:

f.cancel {
   print("Canceled")
}

如果你想发送同步请求, 请使用 FireDispatch:

let f = Fire.build(HTTPMethod: .GET, url: api.stringValue, timeout: timeout, dispatch: dispatch)

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.