RapidFire is a simple networking library. It is suitable for casual use such as prototyping and example project. It wraps URLSession and is written in Swift.
- Swift 5
- iOS 8.0 or later
- Chainable Request
- GET / POST / PUT / PATCH / DELETE
- URL / JSON Parameter Encoding
- multipart/form-data
- JSON to Array / JSON to Dictionary Helper Method
github "keygx/RapidFire"
- Swift 5, tag "swift5"
- Swift 4.2, tag "swift4.2"
- Swift 4.1, tag "swift4.1"
- Swift 4.0, tag "swift4.0"
RapidFire(.get, "https://example.com/users")
.setCompletionHandler({ (response: RapidFire.Response) in
switch response.result {
case .success:
// success
case .failure:
// failure
}
})
.fire()
RapidFire(HTTP Method, baseURL)
// HTTP Method
public enum HTTPMethod: String {
case get = "GET"
case post = "POST"
case put = "PUT"
case patch = "PATCH"
case delete = "DELETE"
}
// baseURL
ex: "https://example.com"
.setPath("/path")
.setHeaders(["x-myheader-1":"value1", "x-myheader-2":"value2"])
.setQuery(["a":"1", "b":"2"]) //?a=1&b=2
.setBody(["a":"1", "b":"2"])
.setJSON(["a":"1", "b":"2"])
.setPartData(["a":"1", "b":"2"])
.setPartData(RapidFire.PartData(name: "image", filename: "sample.png", value: imageData, mimeType: "image/png"))
.setTimeout(30) //sec.
.setRetry(3) //default interval 15 sec.
.setRetry(3, intervalSec: 30)
.setCompletionHandler({ (response: RapidFire.Response) in
switch response.result {
case .success:
print("success:\n \(response.statusCode as Any): \(response.response as Any)")
print(response.toDictionary())
case .failure:
print("error:\n \(response.statusCode as Any): \(response.error as Any)")
}
})
public enum Result {
case success
case failure
}
public var result: Result
public var statusCode: Int?
public var data: Data?
public var response: URLResponse?
public var error: Error?
// Convert JSON to Dictionary
public func toDictionary() -> [String: Any]
// Convert JSON to Array
public func toArray() -> [[String: Any]]
// Convert JSON to String
public func toString() -> String
// Convert JSON to Dictionary
RapidFire.Util.toDictionary(from: response.data)
// Convert JSON to Array
RapidFire.Util.toArray(from: response.data)
// Convert JSON to String
RapidFire.Util.toString(from: response.data)
// Convert to JSON
RapidFire.Util.toJson(from: ["a":"1", "b":"2"])
RapidFire is released under the MIT license. See LICENSE for details.
Yukihiko Kagiyama (keygx) https://twitter.com/keygx