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
Meet CombineNetworking. Super lightweight and crazy easy to use framework to help you create and handle your network requests in a convenient way.
5
-
Besides basic network requests, CombineNetworking allows you to easily send your requests securely with a simple SSL and Certificate pinning mechanisms. But that's not all. With CombineNetworking you can also effortlessly handle authorization tokens with built-in automatic authorization mechanism.
3
+
# SwiftNet
4
+
Meet SwiftNet. Super lightweight and crazy easy to use framework to help you create and handle your network requests in a convenient way.
5
+
Besides basic network requests, SwiftNet allows you to easily send your requests securely with a simple SSL and Certificate pinning mechanisms. But that's not all. With SwiftNet you can also effortlessly handle authorization tokens with built-in automatic authorization mechanism.
6
6
7
7
## Installation (using CocoaPods)
8
8
9
9
`pod 'CombineNetworking'`
10
10
11
-
##### Note that in order to use CombineNetworking, your iOS Deployment Target has to be 13.0 or newer. If you code for macOS, your Deployment Target has to be 10.15 or newer.
11
+
##### Note that in order to use SwiftNet, your iOS Deployment Target has to be 13.0 or newer. If you code for macOS, your Deployment Target has to be 10.15 or newer.
12
12
13
-
#### CombineNetworking 2.0.0 and above won't be available on CocoaPods unless SwiftSyntax package (which is required to enable Swift Macros) becomes available on CocoaPods. To fetch the latest versions, please use SPM (Swift Package Manager).
13
+
#### SwiftNet 2.0.0 and above won't be available on CocoaPods unless SwiftSyntax package (which is required to enable Swift Macros) becomes available on CocoaPods. To fetch the latest versions, please use SPM (Swift Package Manager).
14
14
15
15
## Key functionalities
16
16
- Sending requests easily using `Endpoint` models
17
17
- SSL and Certificate pinning with just 2 lines of code
18
-
- WebSocket connection support with `CNWebSocket`
18
+
- WebSocket connection support with `SNWebSocket`
19
19
- Secure access token storage with Keychain
20
20
- Access token storing strategy - configure `global`, `endpoint specific` (`default`) or `custom` strategy for all or just some endpoints
To turn SSL and/or Certificate pinning in your app just add:
77
77
78
78
```Swift
79
-
CNConfig.pinningModes= [.ssl, .certificate]
79
+
SNConfig.pinningModes= [.ssl, .certificate]
80
80
```
81
81
82
-
Please remember that SSL/Certificate pinning requires certificate file to be attached in your project. Certificates and SSL keys are autmatically loaded by CombineNetworking.
82
+
Please remember that SSL/Certificate pinning requires certificate file to be attached in your project. Certificates and SSL keys are autmatically loaded by SwiftNet.
83
83
84
84
### Automatic authorization mechanism
85
85
86
-
Handling authorization callbacks with CombineNetworking is ridiculously easy. To use it with your `Endpoint` all you have to do is to add `requiresAccessToken` and `callbackPublisher` fields as presented below:
86
+
Handling authorization callbacks with SwiftNet is ridiculously easy. To use it with your `Endpoint` all you have to do is to add `requiresAccessToken` and `callbackPublisher` fields as presented below:
See? Easy peasy! Keep in mind that your token model has to conform to `AccessTokenConvertible`.
117
117
118
-
### CNConfig properties and methods
118
+
### SNConfig properties and methods
119
119
120
120
-`pinningModes` - turns on/off SSL and Certificate pinning. Available options are `.ssl`, `.certificate` or both.
121
121
-`sitesExcludedFromPinning` - list of website addresses excluded from SSL/Certificate pinning check
122
122
-`defaultJSONDecoder` - use this property to set globally your custom JSONDecoder
123
123
-`defaultAccessTokenStrategy` - global strategy for storing access tokens. Available options are `.global` and `.custom(String)`.
124
-
-`keychainInstance` - keychain instance used by CombineNetworking to store/fetch access tokens from Apple's Keychain. If not provided, safe storage will be turned off (more info below)
125
-
-`accessTokenStorage` - an instance of an object implementing AccessTokenStorage protocol. It's used to manipulate access token. By default it uses built-in `CNStorage`. To use different storage, provide your own instance.
124
+
-`keychainInstance` - keychain instance used by SwiftNet to store/fetch access tokens from Apple's Keychain. If not provided, safe storage will be turned off (more info below)
125
+
-`accessTokenStorage` - an instance of an object implementing AccessTokenStorage protocol. It's used to manipulate access token. By default it uses built-in `SNStorage`. To use different storage, provide your own instance.
126
126
-`accessTokenErrorCodes` - array containing error codes that should trigger access token refresh action. Default: [401].
127
127
128
128
### Access Token Strategies
129
129
130
-
CombineNetworking allows you to specify access token strategies globally as well as individually for each endpoint. You can specify your strategy by setting it for `CNConfig.defaultAccessTokenStrategy` or inside your `Endpoint` by setting value for field `accessTokenStrategy`.
130
+
SwiftNet allows you to specify access token strategies globally as well as individually for each endpoint. You can specify your strategy by setting it for `SNConfig.defaultAccessTokenStrategy` or inside your `Endpoint` by setting value for field `accessTokenStrategy`.
131
131
Available options are:
132
132
-`.global` - uses global label to store access token
133
133
-`.custom(String)` - with this option you can specify your own label to store access token and use it among as many endpoints as you wish
134
134
135
-
Thanks to access token strategy being set both globally (via `CNConfig`) and individually (inside `Endpoint`), you can mix different strategies in your app!
135
+
Thanks to access token strategy being set both globally (via `SNConfig`) and individually (inside `Endpoint`), you can mix different strategies in your app!
136
136
137
137
### Access Token manipulations
138
138
@@ -150,7 +150,7 @@ Available methods are:
150
150
151
151
### Event logging
152
152
153
-
CombineNetworking's CNProvider uses iOS built-in Logger (if running on iOS 14 or newer) and custom debug-mode-only logger by default for each and every request.
153
+
SwiftNet's SNProvider uses iOS built-in Logger (if running on iOS 14 or newer) and custom debug-mode-only logger by default for each and every request.
154
154
155
155
### Network connection monitor
156
156
@@ -161,7 +161,7 @@ If you want to subscribe to a network connection monitor's publisher, you can do
CombineNetworking allows you to store your access tokens in keychain. Using keychain to store your access tokens requires you to provide keychain instance by setting value of `CNConfig.keychainInstance`.
181
+
SwiftNet allows you to store your access tokens in keychain. Using keychain to store your access tokens requires you to provide keychain instance by setting value of `SNConfig.keychainInstance`.
182
182
183
-
Please remember Apple's Keychain doesn't automatically remove entries created by an app upon its deletion. Do not worry, however. Only your app can access those entries, nevertheless, it's up to you to make sure those are removed from keychain if not needed anymore. CombineNetworking provides method `CNConfig.removeAccessToken(...)` to help you do it.
183
+
Please remember Apple's Keychain doesn't automatically remove entries created by an app upon its deletion. Do not worry, however. Only your app can access those entries, nevertheless, it's up to you to make sure those are removed from keychain if not needed anymore. SwiftNet provides method `SNConfig.removeAccessToken(...)` to help you do it.
@@ -202,22 +202,22 @@ If you want to subscribe to a publisher but doesn't want to immediately decode t
202
202
203
203
### Error handling
204
204
205
-
In case of request failure, CombineNetworking returns stuct of type `CNError` reflected as `Error`.
205
+
In case of request failure, SwiftNet returns stuct of type `SNError` reflected as `Error`.
206
206
207
207
```Swift
208
-
publicstructCNError: Error{
208
+
publicstructSNError: Error{
209
209
let type: ErrorType
210
-
let details: CNErrorDetails?
210
+
let details: SNErrorDetails?
211
211
let data: Data?
212
212
}
213
213
```
214
214
215
215
Available error types are: `failedToBuildRequest`, `failedToMapResponse`, `unexpectedResponse`, `authenticationFailed`, `notConnected`, `emptyResponse`, `noInternetConnection` and `conversionFailed`.
216
216
217
-
`CNErrorDetails` looks like following:
217
+
`SNErrorDetails` looks like following:
218
218
219
219
```Swift
220
-
publicstructCNErrorDetails {
220
+
publicstructSNErrorDetails {
221
221
publiclet statusCode: Int
222
222
publiclet localizedString: String
223
223
publiclet url: URL?
@@ -232,8 +232,8 @@ public struct CNErrorDetails {
232
232
If you want to run simple tests on your request, just to confirm the status code of the response met the expectations set for a given endpoint you can just run `testRaw()` method like this:
233
233
234
234
```Swift
235
-
finalclassCombineNetworkingTests: XCTestCase {
236
-
privatelet provider =CNProvider<RemoteEndpoint>()
235
+
finalclassSwiftNetTests: XCTestCase {
236
+
privatelet provider =SNProvider<RemoteEndpoint>()
237
237
238
238
functestTodoFetch() throws {
239
239
let expectation =expectation(description: "Test todo fetching request")
@@ -251,8 +251,8 @@ final class CombineNetworkingTests: XCTestCase {
251
251
... and if you want to test your request by confirming both the status code and the response model, use `test()` method like this:
252
252
253
253
```Swift
254
-
finalclassCombineNetworkingTests: XCTestCase {
255
-
privatelet provider =CNProvider<RemoteEndpoint>()
254
+
finalclassSwiftNetTests: XCTestCase {
255
+
privatelet provider =SNProvider<RemoteEndpoint>()
256
256
257
257
functestTodoFetchWithModel() throws {
258
258
let expectation =expectation(description: "Test todo fetching request together with its response model")
@@ -271,10 +271,10 @@ You can also use mocked data in your tests. To do so, just add `mockedData` to y
271
271
272
272
### WebSockets
273
273
274
-
CombineNetworking also allows you to connect with WebSockets effortlessly. Simply use `CNWebSocket` like this:
274
+
SwiftNet also allows you to connect with WebSockets effortlessly. Simply use `SNWebSocket` like this:
275
275
276
276
```Swift
277
-
let webSocket =CNWebSocket(url: URL(string: "wss://socketsbay.com/wss/v2/2/demo/")!)
277
+
let webSocket =SNWebSocket(url: URL(string: "wss://socketsbay.com/wss/v2/2/demo/")!)
278
278
webSocket.connect()
279
279
webSocket.listen { result in
280
280
switch result {
@@ -301,7 +301,7 @@ If you want to close connection, just call `webSocket.disconnect()`.
301
301
302
302
## Macro-powered networking
303
303
304
-
From release 2.0.0 CombineNetworking introduces new way of building and executing network requests.
304
+
From release 2.0.0 SwiftNet introduces new way of building and executing network requests.
From version 2.0.1 CombineNetworking allows you to speed things up even more by generating EndpointBuilders with descriptors. Thanks to descriptors, you can extract endpoint setup to reduce number of lines required to build working endpoint.
408
+
From version 2.0.1 SwiftNet allows you to speed things up even more by generating EndpointBuilders with descriptors. Thanks to descriptors, you can extract endpoint setup to reduce number of lines required to build working endpoint.
0 commit comments