Resty 1.0.0

Resty 1.0.0

Maintained by Satish Babariya.



Resty 1.0.0

  • By
  • Satish Babariya

resty

Simple HTTP Networking Library with Async/Await and Codable.

let todos: [Todo] = try await FakeAPI.todos.request()

Language: Swift 5 Version License Platform Swift Package Manager

Installation

CocoaPods

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

pod 'Resty'

Then, run the following command:

$ pod install

Swift Package Manager

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

dependencies: [
    .package(url: "https://github.com/satishbabariya/Resty.git", .upToNextMajor(from: "1.0.0"))
]

Get started

Import SwiftyContacts into your porject

import Resty

Request with codable async/await

let todos: [Todo] = try await FakeAPI.todos.request()

Request with codable

FakeAPI.todos.request(type: [Todo].self) { result in
     switch result {
        case let .success(todos):
                // Array of [Todo]                
        case let .failure(error):
                // error                
     }     
}

REST API Setup

struct Todo: Codable {
    let id: Int
    let title: String
    let completed: Bool
}

enum FakeAPI: Resty {
    case todos
}

extension FakeAPI {
    var host: String {
        return "https://jsonplaceholder.typicode.com/"
    }

    var path: String {
        return ""
    }

    var endpoint: String {
        switch self {
        case .todos:
            return "todos"
        }
    }

    var method: HTTPMethod {
        switch self {
        case .todos:
            return .get
        }
    }

    var parameters: [String: Any]? {
        return nil
    }

    var headers: [String: String]? {
        return nil
    }
}

Author

Satish Babariya, [email protected]

License

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