Latest 1.0.0
Homepage https://github.com/gabrieltheodoropoulos/GTRest
License MIT
Platforms ios 11.0
Authors

A lightweight Swift library for making web requests and consuming RESTful APIs!

Platform
Language
License
Version

Adding GTRest to your project

Using CocoaPods

In your Podfile add:

pod 'GTRest'

Don’t forget to import GTRest anywhere you want to use it in your project:

import GTRest

Manually

Download or clone the repository, and add the files in GTRest/Source directory to your project.

Usage

Making web requests with GTRest is really simple and straightforward!

See the Documentation generated by jazzy on how to use GTRest.

A quick example:

let url = URL(...) // A URL object.
let rest = GTRest()

// Set any request HTTP headers:
rest.requestHttpHeaders.add(value: "application/json", forKey: "Accept")

// Set any URL query parameters:
rest.urlQueryParameters.add(value: "2", forKey: "page")

// Make a request.
rest.makeRequest(toURL: url, httpMethod: .get) { [unowned self] (results) in // or [weak self] (results) in
    // Access data returned by the server:
    if let data = results.data {
        // Perform app-specific actions
    }

    // Access the response:
    if let response = results.response {
        // Do something with the response object if necessary.
        // Checking the HTTP status code :
        if (200...299).contains(response.httpStatusCode) {
            // Successful request.
        } else { ... }
    }

    // Access the error:
    if let error = results.error {
        // Do something with the error.
    }

    // Always update your UI on main thread:
    DispatchQueue.main.async {
        // Update UI.
    }
}

Requirements

iOS 11.0 and above.

See Also

You might be also interested in GTNetMon, another Swift library to get network status and connection information, and to monitor for network changes.

Latest podspec

{
    "name": "GTRest",
    "version": "1.0.0",
    "summary": "A lightweight Swift library for making web requests and consuming RESTful APIs!",
    "description": "GTRest makes it super easy and straightforward to perform web requests and work with RESTful APIs in iOS projects using Swift.",
    "homepage": "https://github.com/gabrieltheodoropoulos/GTRest",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Gabriel Theodoropoulos": "[email protected]"
    },
    "social_media_url": "https://twitter.com/gabtheodor",
    "platforms": {
        "ios": "11.0"
    },
    "source": {
        "git": "https://github.com/gabrieltheodoropoulos/GTRest.git",
        "tag": "1.0.0"
    },
    "source_files": "GTRest/Source/*.{swift}",
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This