HTTPEngine

Swift PublishDocumentation Docs SPM compatible codebeat badge License

A convenience wrapper around Swift’s Combine and URLSession to make URLRequests

SPM

dependencies: [
    .package(url: "https://github.com/JZDesign/HTTPEngine.git", .upToNextMajor(from: "0.2.0"))
],

Usage

Get and decode

struct Recipes: Codable {
    let id: String
    let imageURLs: [String]
    let title: String
    let ingredients: [Ingredient]
    let steps: [Step]
}

let engine = HTTPEngine()

engine
    .get([Recipes].self, url: "https://my-recipes.com/baby-back-ribs")
    .assertNoFailure() // don't do this
    .sink { recipes in
}

Post with encode and decode

struct NewUser: Codable {
    let userName, email, password: String
}

struct NewUserResponse: Codable {
    let id, accessToken, scope: String
}

let newUser = NewUser(userName: "Dudemus", email: "mydude1@electronmail.com", password: "This_R3@LLy_5h0uld_b3_encrypt3d")
let engine = HTTPEngine()

engine
    .post(NewUserResponse.self, url: "https://auth.somedomain.com", body: newUser, validator: { $0 == 202 })
    .catch {
        // handle non 202 response or other errors
    }
    .assign(to: \.user, on: UserStore)

Standard Requests

let engine = HTTPEngine()

engine
    .makeRequest(method: .delete, url: "https://not-google.com/", body: data, header: headers, validator: { $0 == 204 })
    .catch {
        // handle non 204 response or other errors
    }
    .sink { data in
        // handle response data
    }

View Documentation

Documentation generated by Jazzy.