Swiftpack.co - Package - JZDesign/HTTPEngine

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.

Github

link
Stars: 1

Used By

Total: 0

Releases

- 2020-08-22 19:47:00

Removes local utility functions and pulls them in from another package

Put, Patch, Delete - 2020-08-21 15:51:43

Adds a few new helper methods and documentation. These methods are very similar to .post

Get, Post and More + better documentation - 2020-08-18 12:47:46

Get, Post and More - 2020-08-18 01:47:29

Release 0.2.0

This release contains convenient helper methods that wrap Swift's Combine + URLSession and supplies an enjoyable and succinct developer experience to:

  • Build and make requests
  • Encode json Body
  • Decode the Json Responses
  • Handle Status Code Validation
  • Return developer friendly errors to work with

What is not in this release

All the desired helper methods patch delete etc.,

Notes

The branch was titled release1.0 by mistake.

Generate Docs - 2020-08-17 20:31:50

This was to test the Jazzy docs generation flow.