Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NikSativa/SmartNetwork
Light weight wrapper around URLSession
https://github.com/NikSativa/SmartNetwork
api async-await fast interception interceptor ios json mac macos plugin rest stoptheline strongly-typed swift visionos watchos
Last synced: 2 months ago
JSON representation
Light weight wrapper around URLSession
- Host: GitHub
- URL: https://github.com/NikSativa/SmartNetwork
- Owner: NikSativa
- License: mit
- Created: 2020-08-26T10:03:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T09:58:30.000Z (2 months ago)
- Last Synced: 2024-10-21T14:24:08.764Z (2 months ago)
- Topics: api, async-await, fast, interception, interceptor, ios, json, mac, macos, plugin, rest, stoptheline, strongly-typed, swift, visionos, watchos
- Language: Swift
- Homepage:
- Size: 534 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmartNetwork
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FSmartNetwork%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/NikSativa/SmartNetwork)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FSmartNetwork%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/NikSativa/SmartNetwork)
[![CI](https://github.com/NikSativa/SmartNetwork/actions/workflows/swift_macos.yml/badge.svg)](https://github.com/NikSativa/SmartNetwork/actions/workflows/swift_macos.yml)Light weight wrapper around URLSession.
## The main features are:
- strong typed responses
> await manager.decodable.request(**TestInfo.self**, address: address)
- predefined API for basic types: *Void, Data, Image, Any(JSON)*
- *async/await* and *closure* strategies in one interface
- use `CustomDecodable` to define your own decoding strategy or type
- **Plugin** is like Android interceptors. Handle every *request-response* in runtime!
+ *Plugins.StatusCode* to handle http status codes or use *StatusCode* directly for easy mapping to human readable enumeration
+ *Plugins.Basic* or *Plugins.Bearer* for easy auth strategy
+ *Plugins.TokenPlugin* to update every request
- **StopTheLine** mechanic to handle any case when you need to stop whole network and wait while you make something: *update auth token, handle Captcha etc..*
- **HTTPStubServer** mocks your own network in runtime. Make your magic while your server are not ready!
- macOS/iOS supports### New structure of network request organization based on that new interface:
```
public protocol RequestManagering {
// MARK: -var pure: PureRequestManager { get }
var decodable: DecodableRequestManager { get }
var void: TypedRequestManager { get }// MARK: - strong
var data: TypedRequestManager { get }
var image: TypedRequestManager { get }
var json: TypedRequestManager { get }// MARK: - optional
var dataOptional: TypedRequestManager { get }
var imageOptional: TypedRequestManager { get }
var jsonOptional: TypedRequestManager { get }// MARK: - custom
func custom(_ type: T.Type) -> TypedRequestManager
}
```### New usage of API with short autocompletion:
```
Task {
let manager = RequestManager.create()
let result = await manager.decodable.request(TestInfo.self, address: address)
switch result {
case .success(let obj):
// do something with response
case .failure(let error):
// do something with error
}
}
```