jghg02 / NET

Network Layer with async and await

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NET

iOS iOS iOS

This library provee all the necessary logic to make a request to any API from your application. This is an implementation using async and await

Requeriments

  • iOS >= 14
  • macOS >= 10.15

Installation

Add NET Client as a dependency through Xcode or directly to Package.swift:

.package(url: "https://github.com/jghg02/NET", branch: "main")

Usage

struct Recipes: Codable {
    let id: String
    let name: String
    let headline: String
    let image: String?
    let preparationMinutes: Int
}


struct RegistrationError: LocalizedError, Codable, Equatable {
    let status: Int
    let message: String

    var errorDescription: String? { message }
}
    let client = NETClient<[Recipes], RegistrationError>()
    let request = NETRequest(url: URL(string: "https://example.com")!)
    switch await client.request(request) {
    case .success(let data):
        print(data)
    case .failure(let error):
        print("Error")
        print(error.localizedDescription)
    }

About

Network Layer with async and await


Languages

Language:Swift 100.0%