Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darrarski/swiftendpoint
Lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications
https://github.com/darrarski/swiftendpoint
combine-framework endpoint networking swift swift-package
Last synced: about 1 month ago
JSON representation
Lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications
- Host: GitHub
- URL: https://github.com/darrarski/swiftendpoint
- Owner: darrarski
- License: gpl-3.0
- Created: 2020-02-08T21:46:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-14T19:24:16.000Z (over 3 years ago)
- Last Synced: 2024-11-30T21:42:26.838Z (about 1 month ago)
- Topics: combine-framework, endpoint, networking, swift, swift-package
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📦 SwiftEndpoint
![Swift v5.1](https://img.shields.io/badge/swift-v5.1-orange.svg)
![Swift Package Manager](https://img.shields.io/badge/swift%20package%20manager-✓-green.svg)
![platforms iOS macOS](https://img.shields.io/badge/platforms-iOS%20macOS-blue.svg)**SwiftEndpoint** is a lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications.
## 🛠 Tech stack
- [Swift](https://swift.org/) 5.1
- [Xcode](https://developer.apple.com/xcode/) 11.3.1
- [iOS](https://www.apple.com/pl/ios/) 13.0
- [macOS](https://www.apple.com/pl/macos/) 10.15## 📝 Description
**`Endpoint`** is a generic function that transforms some `Request` into some `Response` publisher:
```swift
typealias Endpoint = (Request) -> AnyPublisher
```### 🧩 Foundation URL networking
Set of helpers for building API clients based on the native [Foundation](https://developer.apple.com/documentation/foundation)'s networking.
**`urlEndpoint`** function creates an `Endpoint` that uses Foundation's networking:
```swift
func urlEndpoint(
requestFactory: @escaping URLRequestFactory,
publisherFactory: @escaping URLResponsePublisherFactory,
responseValidator: @escaping URLResponseValidator,
responseDecoder: @escaping URLResponseDecoder
) -> Endpoint
```**`URLRequestFactory`** is a generic function that transforms some `Request` into `URLRequest`, optionally throwing an error:
```swift
typealias URLRequestFactory = (Request) throws -> URLRequest
```**`URLResponsePublisherFactory`** is a function that transforms `URLRequest` into `URLResponsePublisher`:
```swift
typealias URLResponsePublisherFactory = (URLRequest) -> URLResponsePublisher
```Convenience extension allows to use `URLSession` as a `URLResponsePublisherFactory`:
```swift
extension URLSession {
var urlResponsePublisherFactory: URLResponsePublisherFactory { get }
}
```**`URLResponsePublisher`** is a combine publisher emitting network responses or failing with networking error:
```swift
typealias URLResponsePublisher = AnyPublisher<(data: Data, response: URLResponse), Error>
```**`URLResponseValidator`** is a function that validates response `Data` and `URLResponse`, optionally throwing validation error:
```swift
typealias URLResponseValidator = (Data, URLResponse) throws -> Void
```**`URLResponseDecoder`** is a generic function that transforms response `Data` and `URLResponse` into some `Response`, optionally throwing decoding error:
```swift
typealias URLResponseDecoder = (Data, URLResponse) throws -> Response
```## 🧰 Installation
**SwiftEndpoint** is compatible with [Swift Package Manager](https://swift.org/package-manager/). You can add it as a dependency to your [Xcode project](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app) or [swift package](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#defining-dependencies).
## 🛠 Development
Running tests:
```sh
swift test
```Developing in [Xcode](https://developer.apple.com/xcode/):
```sh
swift package generate-xcodeproj
open -a SwiftEndpoint.xcodeproj
```## ☕️ Do you like the project?
## 📄 License
Copyright © 2020 Dariusz Rybicki Darrarski
License: [GNU GPLv3](LICENSE)