Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dbsystel/DBNetworkStack
DBNetworkStack is a network abstraction for fetching request and mapping them to model objects
https://github.com/dbsystel/DBNetworkStack
Last synced: about 1 month ago
JSON representation
DBNetworkStack is a network abstraction for fetching request and mapping them to model objects
- Host: GitHub
- URL: https://github.com/dbsystel/DBNetworkStack
- Owner: dbsystel
- License: mit
- Created: 2016-10-04T11:00:29.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-04T07:53:43.000Z (6 months ago)
- Last Synced: 2024-10-29T10:45:32.191Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 4.87 MB
- Stars: 35
- Watchers: 9
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - DBNetworkStack - Resource-oritented networking which is typesafe, extendable, composeable and makes testing a lot easier. (Networking / Video)
- awesome-ios-star - DBNetworkStack - Resource-oritented networking which is typesafe, extendable, composeable and makes testing a lot easier. (Networking / Video)
README
# DBNetworkStack
[![Build Status](https://travis-ci.org/dbsystel/DBNetworkStack.svg?branch=develop)](https://travis-ci.org/dbsystel/DBNetworkStack)
[![codebeat badge](https://codebeat.co/badges/e438e768-249d-4e9f-8dd8-32928537740e)](https://codebeat.co/projects/github-com-dbsystel-dbnetworkstack-develop)
[![codecov](https://codecov.io/gh/dbsystel/DBNetworkStack/branch/develop/graph/badge.svg)](https://codecov.io/gh/dbsystel/DBNetworkStack)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)| | Main Features |
| --------- | ------------------------------ |
| ๐ก | Typed network resources |
| ๐ | Value oriented architecture |
| ๐ | Exchangeable implementations |
| ๐ | Extendable API |
| ๐นย ย ย ย | Composable Features ย ย ย ย ย |
| โ | Fully unit tested |
| ๐ย | [Documented here](https://dbsystel.github.io/DBNetworkStack/)ย ย ย ย ย ย |The idea behind this project comes from this [talk.objc.io article](https://talk.objc.io/episodes/S01E01-networking).
## Basic Demo
Lets say you want to fetch a ``html`` string.First you have to create a service, by providing a network access. You can use URLSession out of the box or provide your own custom solution by implementing ```NetworkAccess```.
```swift
let networkAccess = URLSession(configuration: .default)
let networkService = BasicNetworkService(networkAccess: networkAccess)```
Create a resource with a request to fetch your data.
```swift
let url = URL(staticString: "https://httpbin.org")
let request = URLRequest(path: "/", baseURL: url, HTTPMethod: .GET)
let resource = Resource(request: request, parse: { String(data: $0, encoding: .utf8) })```
Request your resource and handle the result
```swift
networkService.request(resource, onCompletion: { htmlText in
print(htmlText)
}, onError: { error in
//Handle errors
})```
## Load types conforming to Swift-`Decodable`
```swift
struct IPOrigin: Decodable {
let origin: String
}let url = URL(staticString: "https://www.httpbin.org")
let request = URLRequest(path: "ip", baseURL: url)let resource = Resource(request: request, decoder: JSONDecoder())
networkService.request(resource, onCompletion: { origin in
print(origin)
}, onError: { error in
//Handle errors
})
```## Accessing HTTPResponse
Request your resource and handle the result & http response. This is similar to just requesting a resulting model.
```swift
networkService.request(resource, onCompletionWithResponse: { origin, response in
print(origin, response)
}, onError: { error in
//Handle errors
})
```## Protocol oriented architecture / Exchangability
The following table shows all the protocols and their default implementations.
| Protocol | Default Implementation |
| -------------------------------- | ---------------------- |
| ```NetworkAccess``` | ```URLSession``` |
| ```NetworkService``` | ```BasicNetworkService``` |
| ```NetworkTask``` | ```URLSessionTask``` |## Composable Features
| Class | Feature |
| -------------------------------- | ---------------------- |
| ```RetryNetworkService``` | Retrys requests after a given delay when an error meets given criteria. |
| ```ModifyRequestNetworkService``` | Modify matching requests. Can be used to add auth tokens or API Keys |
| ```NetworkServiceMock``` | Mocks a NetworkService. Can be use during unit tests |## Requirements
- iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
## Installation
### Swift Package Manager
[SPM](https://swift.org/package-manager/) is integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Specify the following in your `Package.swift`:
```swift
.package(url: "https://github.com/dbsystel/DBNetworkStack", from: "2.1.0"),
```## Contributing
Feel free to submit a pull request with new features, improvements on tests or documentation and bug fixes. Keep in mind that we welcome code that is well tested and documented.## Contact
Lukas Schmidt ([Mail](mailto:[email protected]), [@lightsprint09](https://twitter.com/lightsprint09)),
Christian Himmelsbach ([Mail](mailto:[email protected]))## License
DBNetworkStack is released under the MIT license. See LICENSE for details.