Skip to content

Commit 3123c34

Browse files
committed
Update README.md
1 parent 867c18d commit 3123c34

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Given are the some of the examples on how you can make use of this utility
3434
4. [Request with MultiPartFormData](https://github.com/codecat15/HttpUtility#post-request-with-multipartformdata)
3535
5. [Request with authentication token](https://github.com/codecat15/HttpUtility#authentication-token)
3636
6. [Customize JSONDecoder in the Utility](https://github.com/codecat15/HttpUtility#token-and-custom-jsondecoder)
37-
7. [HUNetworkError]
37+
7. [HUNetworkError](https://github.com/codecat15/HttpUtility/tree/multipart-form-data-format#hunetworkerror)
3838

3939
## GET Request example
4040

@@ -105,15 +105,16 @@ utility.request(huRequest: request, resultType: PhoneResponse.self) { (response)
105105
## POST request with MultiPartFormData
106106

107107
```swift
108+
109+
let utility = HttpUtility.shared
108110
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/TestMultiPart")
109111

110112
// your request model struct should implement the encodable protocol
111113
let requestModel = RequestModel(name: "Bruce", lastName: "Wayne")
114+
112115
let multiPartRequest = HUMultiPartRequest(url: requestUrl!, method: .post, request: requestModel)
113116

114-
let request = HURequest(url: requestUrl!, method: .get)
115-
let utility = HttpUtility.shared
116-
_utility.requestWithMultiPartFormData(multiPartRequest: multiPartRequest, responseType: TestMultiPartResponse.self) { (response) in
117+
utility.requestWithMultiPartFormData(multiPartRequest: multiPartRequest, responseType: TestMultiPartResponse.self) { (response) in
117118
switch response
118119
{
119120
case .success(let serviceResponse):
@@ -122,15 +123,15 @@ _utility.requestWithMultiPartFormData(multiPartRequest: multiPartRequest, respon
122123
case .failure(let error):
123124
// code to handle failure
124125
}
125-
expectation.fulfill()
126126
}
127127
```
128128

129129
## Authentication Token
130130

131131
```swift
132-
let requestUrl = URL(string: "https://httpbin.org/get")
133-
let utility = HttpUtility(token: "your authentication token")
132+
let token = "your_token"
133+
let utility = HttpUtility.shared
134+
utility.authenticationToken = token
134135
```
135136

136137
if you are using a basic or a bearer token then make sure you put basic or bearer before your token starts
@@ -167,13 +168,12 @@ utility.customJsonDecoder = customJsonDecoder
167168
At times when you pass the token and the default JSONDecoder is just not enough, then you may use the init method of the utility to pass the token and a custom JSONDecoder both to make the API request and parse the JSON response
168169

169170
```swift
171+
let utility = HttpUtility.shared
170172
let customJsonDecoder = JSONDecoder()
171173
customJsonDecoder.dateEncoding = .millisecondsSince1970
172174

173175
let bearerToken = "bearer your_token"
174176

175-
let utility = HttpUtility.shared
176-
177177
utility.customJsonDecoder = customJsonDecoder
178178
utility.authenticationToken = token
179179

@@ -183,10 +183,14 @@ utility.authenticationToken = token
183183

184184
The HUNetworkError structure provides in detail description beneficial for debugging purpose, given are the following properties that will be populated in case an error occurs
185185

186-
1. Status: This will contain the HTTPStatus code for the request (200)
187-
2. ServerResponse: This will be the JSON string of the response you received from the server. (not to be confused with error parameter) on error if server returns the error JSON data that message will be decoded to human readable string.
188-
3. RequestUrl: The request URL that you just called.
189-
4. RequestBody: If you get failure on POST request this property would contain a string representation of the HTTPBody that was sent to the server.
190-
5. Reason: This property would contain the debug description from the error closure parameter.
186+
1. ### Status: This will contain the HTTPStatus code for the request (200)
187+
188+
2. ### ServerResponse: This will be the JSON string of the response you received from the server. (not to be confused with error parameter) on error if server returns the error JSON data that message will be decoded to human readable string.
189+
190+
3. ### RequestUrl: The request URL that you just called.
191+
192+
4. ### RequestBody: If you get failure on POST request this property would contain a string representation of the HTTPBody that was sent to the server.
193+
194+
5. ### Reason: This property would contain the debug description from the error closure parameter.
191195

192196
This utility is for performing basic tasks, and is currently evolving, but if you have any specific feature in mind then please feel free to drop a request and I will try my best to implement it

0 commit comments

Comments
 (0)