You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+128-5Lines changed: 128 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,24 @@
1
1
# ObservableNetworking
2
2
3
-
A simple, yet flexible, networking library that allows the use of RxSwift to return observable from network requests.
3
+
A simple and flexible networking library that allows the use of RxSwift and Combine to return observable data from network requests.
4
4
5
5
6
-
###How to use
6
+
## How to use
7
7
8
-
To get started, you will need to let the framework know a little about your different enviroments by defining an `enum` that conforms to `NetworkEnvironment`. This will allow the framework to build the desired network requests and URLs it needs.
8
+
### Set up the Environment
9
+
10
+
To get started, the framework needs to know a little about the possible environments which can be accomplished by defining an `enum` that conforms to `NetworkEnvironment`. This will allow the framework to build the desired network requests and URLs it needs.
Once the environment has been defined it is time to initialize the framework by passing in your selected environment. This framework conforms to the `ObservableNetwork` protocol so that it is easily mocked for testing. All that is then needed is to grab the `network` from the instantiation.
48
+
### Initializing `ObservableNetworking`
49
+
50
+
Once the environment has been defined it is time to initialize the framework by passing in the selected environment. This framework conforms to the `ObservableNetwork` protocol so that it is easily mocked for testing. All that is then needed is to grab the `network` from the instantiation.
45
51
46
52
```Swift
47
53
let networkingFramework =ObservableNetworking(environment: .dev)
No matter which reactive framework is chosen, each type of network request has the same basic components which will need to be configured for the request.
73
+
74
+
#### Method - `HTTPMethod`
75
+
76
+
The `method` is the HTTP verb that indicates what kind of request is to be made. Some of the most common methods are `.get` ("GET") and .post ("POST"). There are a number more that are supported, all of which can be found [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods).
77
+
78
+
#### Endpoint - `String`
79
+
80
+
The `endpoint` is the last portion of the URL and will specify to the API what information you wish to send or receive as a result of the request.
81
+
82
+
#### Parameters - `[String : Any]?`
83
+
84
+
The `parameters` comprise the information that the API needs to properly process the request. For `.get` requests the parameters are added on to the end of the URL. For `.post`, `.patch` or `.put` requests the parameters are serialized and added as the request's `httpBody`.
85
+
86
+
#### Headers - `[String : String]?`
87
+
88
+
The `headers` allow additional information to be passed along in a request or response. The framework automatically adds the `Accept: json` header in each request, but if needed, it will be overridden if another value is passed in with the `Accept` name.
89
+
90
+
For authenticated requests, an authorization cookie is automatically added (the cookie will automatically be stored when it comes back from the API) to be authenticated by the API. Authenticated requests also automatically get the `Accept: json` header as well.
91
+
92
+
### Choose the reactive framework
93
+
94
+
Now that the networking is instantiated and has an environment to build requests, it is time to decide which reactive framework to use for observing requests. `ObservableNetworking` supports both [RxSwift](https://github.com/ReactiveX/RxSwift) and [Combine](https://developer.apple.com/documentation/combine) out of the box.
95
+
96
+
**Important Note**:
97
+
98
+
Apple's Combine framework is only supported on:
99
+
* iOS 13.0 and later
100
+
* OSX 10.15 and later
101
+
* Mac Catalyst 13.0 and later
102
+
* tvOS 13.0 and later
103
+
* watchOS 6.0 and later
104
+
105
+
If you need to support previous versions, then you will need to use RxSwift
0 commit comments