Skip to content

Commit c379c75

Browse files
committed
Update README.md
1 parent e42a0d5 commit c379c75

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ Given are the some of the examples on how you can make use of this utility
3939
## GET Request example
4040

4141
```swift
42+
let utility = HTTPUtility.shared // using the shared instance of the utility to make the API call
4243
let requestUrl = URL(string: "http://demo0333988.mockable.io/Employees")
4344
let request = HURequest(url: requestUrl!, method: .get)
44-
let utility = HTTPUtility.shared
45+
4546
utility.request(huRequest: request, resultType: Employees.self) { (response) in
4647
switch response
4748
{
@@ -60,12 +61,14 @@ let requestUrl = URL(string: "http://demo0333988.mockable.io/Employees")
6061
The httpUtility has an extra parameter "requestBody" where you should attach the data that you have to post to the server, in the given example the RegisterUserRequest is a struct inheriting from the [Encodable protocol](https://developer.apple.com/documentation/swift/encodable)
6162

6263
```swift
64+
let utiltiy = HttpUtility.shared // using the shared instance of the utility to make the API call
65+
6366
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/api/User/RegisterUser")
6467
let registerUserRequest = RegisterUserRequest(firstName: "code", lastName: "cat15", email: "[email protected]", password: "1234")
68+
6569
let registerUserBody = try! JSONEncoder().encode(registerUserRequest)
6670
let request = HURequest(url: requestUrl!, method: .post, requestBody: registerUserBody)
6771

68-
let utiltiy = HttpUtility.shared
6972
utility.request(huRequest: request, resultType: RegisterResponse.self) { (response) in
7073
switch response
7174
{
@@ -81,13 +84,13 @@ let request = HURequest(url: requestUrl!, method: .post, requestBody: registerUs
8184
## GET request with Query string parameters
8285

8386
```swift
87+
let utiltiy = HttpUtility.shared // using the shared instance of the utility to make the API call
8488
let request = PhoneRequest(color: "Red", manufacturer: nil)
8589

8690
// using the extension to convert the encodable request structure to a query string url
8791
let requestUrl = request.convertToQueryStringUrl(urlString:"https://api-dev-scus-demo.azurewebsites.net/api/Product/GetSmartPhone")
8892

8993
let request = HURequest(url: requestUrl!, method: .get)
90-
let utility = HttpUtility.shared
9194
utility.request(huRequest: request, resultType: PhoneResponse.self) { (response) in
9295

9396
switch response
@@ -106,7 +109,7 @@ utility.request(huRequest: request, resultType: PhoneResponse.self) { (response)
106109

107110
```swift
108111

109-
let utility = HttpUtility.shared
112+
let utiltiy = HttpUtility.shared // using the shared instance of the utility to make the API call
110113
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/TestMultiPart")
111114

112115
// your request model struct should implement the encodable protocol
@@ -129,8 +132,8 @@ utility.requestWithMultiPartFormData(multiPartRequest: multiPartRequest, respons
129132
## Authentication Token
130133

131134
```swift
132-
let token = "your_token"
133135
let utility = HttpUtility.shared
136+
let token = "your_token"
134137
utility.authenticationToken = token
135138
```
136139

@@ -183,14 +186,14 @@ utility.authenticationToken = bearerToken
183186

184187
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
185188

186-
1. ##### Status: ##### This will contain the HTTPStatus code for the request (200)
189+
1. **Status:** This will contain the HTTPStatus code for the request (200)
187190

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.
191+
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.
189192

190-
3. ##### RequestUrl: ##### The request URL that you just called.
193+
3. **RequestUrl:** The request URL that you just called.
191194

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.
195+
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.
193196

194-
5. ##### Reason: ##### This property would contain the debug description from the error closure parameter.
197+
5. **Reason:** This property would contain the debug description from the error closure parameter.
195198

196199
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)