11# HTTPEngine
2- ![ Swift] ( https://github.com/JZDesign/HTTPEngine/workflows/Swift/badge.svg ) [ ![ SPM compatible] ( https://img.shields.io/badge/SPM-compatible -e66f20.svg?style=flat )] ( https://github.com/apple/swift-package-manager ) [ ![ Docs] ( https://img.shields.io/badge/Jazzy-Documentation-634fb3.svg?style=flat )] ( https://jzdesign.github.io/HTTPEngine/ )
2+ ![ Swift] ( https://github.com/JZDesign/HTTPEngine/workflows/Swift/badge.svg ) [ ![ SPM compatible] ( https://img.shields.io/badge/SPM-Compatible -e66f20.svg?style=flat )] ( https://github.com/apple/swift-package-manager ) [ ![ Docs] ( https://img.shields.io/badge/Jazzy-Documentation-634fb3.svg?style=flat )] ( https://jzdesign.github.io/HTTPEngine/ ) [ ![ License ] ( https://img.shields.io/badge/License-MIT-335577.svg?style=flat )] ( https://github.com/JZDesign/HTTPEngine/blob/master/LICENSE )
33
44A convenience wrapper around Swift's Combine and URLSession to make ` URLRequests `
55
@@ -13,3 +13,64 @@ dependencies: [
1313## [ View Documentation] ( https://jzdesign.github.io/HTTPEngine/ )
1414
1515Documentation generated by [ Jazzy] ( https://github.com/realm/jazzy ) .
16+
17+
18+ ## Usage
19+ ### Get and decode
20+ ``` swift
21+ struct Recipes : Codable {
22+ let id: String
23+ let imageURLs: [String ]
24+ let title: String
25+ let ingredients: [Ingredient]
26+ let steps: [Step]
27+ }
28+
29+ let engine = HTTPEngine ()
30+
31+ engine
32+ .get ([Recipes].self , url : " https://my-recipes.com/baby-back-ribs" )
33+ .assertNoFailure () // don't do this
34+ .sink { recipes in
35+ }
36+
37+ ```
38+
39+ ### Post with encode and decode
40+
41+ ``` swift
42+ struct NewUser : Codable {
43+ let userName, email, password: String
44+ }
45+
46+ struct NewUserResponse : Codable {
47+ let id, accessToken, scope: String
48+ }
49+
50+ let newUser
= NewUser (
userName :
" Dudemus" ,
email :
" [email protected] " ,
password :
" This_R3@LLy_5h0uld_b3_encrypt3d" )
51+ let engine = HTTPEngine ()
52+
53+ engine
54+ .post (NewUserResponse.self , url : " https://auth.somedomain.com" , body : newUser, validator : { $0 == 202 })
55+ .catch {
56+ // handle non 202 response or other errors
57+ }
58+ .assign (to : \.user , on : UserStore)
59+
60+ ```
61+
62+ ### Standard Requests
63+
64+ ``` swift
65+ let engine = HTTPEngine ()
66+
67+ engine
68+ .makeRequest (method : .delete , url : " https://not-google.com/" , body : data, header : headers, validator : { $0 == 204 })
69+ .catch {
70+ // handle non 204 response or other errors
71+ }
72+ .sink { data in
73+ // handle response data
74+ }
75+
76+ ```
0 commit comments