Thanks to visit codestin.com
Credit goes to github.com

Skip to content

charlesfries/SwiftyFetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyFetch

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

// AppDelegate.swift

import SwiftyFetch

Fetch.shared.setBaseUrl("https://jsonplaceholder.typicode.com/")
Fetch.shared.setAPIKey("xxxxxxxxxxxxxxxxxxxx")

UserDefaults.standard.set("accessToken", forKey: "xxxxxxxxxxxxxxxxxxxx") // <- for testing; should be set by your auth controller
if let accessToken = UserDefaults.standard.value(forKey: "accessToken") as? String {
    Fetch.shared.setToken(accessToken)
}
// ViewController.swift

import SwiftyFetch

Fetch.shared.request("posts", method: "POST", body: ["limit": 25]) { result in
    switch result {
    case .success(let response):
        if response.ok {
            let json = response.json
            print("JSON: \(json)")
        } else {
            print("HTTP: \(response.status), \(response.statusText)")
        }
    case .failure(let error):
        print(error)
    }
}
response.status // HTTP status code
response.statusText // HTTP status description
response.ok // true if 200
response.headers // HTTP headers
response.url // full requested URL
response.text // string representation of response data
response.json // JSON response data

Requirements

Installation

SwiftyFetch is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftyFetch', :git => 'https://github.com/charlesfries/SwiftyFetch.git'

Author

charlesfries, [email protected]

License

SwiftyFetch is available under the MIT license. See the LICENSE file for more info.

About

A fetch-like CocoaPod for programmatically making web requests with JSON responses on iOS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published