Add Buy me a coffee button to README.md
SwiftEndpoint is a lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications.
Endpoint is a generic function that transforms some Request into some Response publisher:
Endpoint
Request
Response
typealias Endpoint<Request, Response> = (Request) -> AnyPublisher<Response, Error>
Set of helpers for building API clients based on the native Foundation‘s networking.
urlEndpoint function creates an Endpoint that uses Foundation’s networking:
urlEndpoint
func urlEndpoint<Request, Response>( requestFactory: @escaping URLRequestFactory<Request>, publisherFactory: @escaping URLResponsePublisherFactory, responseValidator: @escaping URLResponseValidator, responseDecoder: @escaping URLResponseDecoder<Response> ) -> Endpoint<Request, Response>
URLRequestFactory<Request> is a generic function that transforms some Request into URLRequest, optionally throwing an error:
URLRequestFactory<Request>
URLRequest
typealias URLRequestFactory<Request> = (Request) throws -> URLRequest
URLResponsePublisherFactory is a function that transforms URLRequest into URLResponsePublisher:
URLResponsePublisherFactory
URLResponsePublisher
typealias URLResponsePublisherFactory = (URLRequest) -> URLResponsePublisher
Convenience extension allows to use URLSession as a URLResponsePublisherFactory:
URLSession
extension URLSession { var urlResponsePublisherFactory: URLResponsePublisherFactory { get } }
URLResponsePublisher is a combine publisher emitting network responses or failing with networking error:
typealias URLResponsePublisher = AnyPublisher<(data: Data, response: URLResponse), Error>
URLResponseValidator is a function that validates response Data and URLResponse, optionally throwing validation error:
URLResponseValidator
Data
URLResponse
typealias URLResponseValidator = (Data, URLResponse) throws -> Void
URLResponseDecoder<Response> is a generic function that transforms response Data and URLResponse into some Response, optionally throwing decoding error:
URLResponseDecoder<Response>
typealias URLResponseDecoder<Response> = (Data, URLResponse) throws -> Response
SwiftEndpoint is compatible with Swift Package Manager. You can add it as a dependency to your Xcode project or swift package.
Running tests:
swift test
Developing in Xcode:
swift package generate-xcodeproj open -a SwiftEndpoint.xcodeproj
Copyright © 2020 Dariusz Rybicki Darrarski
License: GNU GPLv3
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
📦 SwiftEndpoint
SwiftEndpoint is a lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications.
🛠 Tech stack
📝 Description
Endpoint
is a generic function that transforms someRequest
into someResponse
publisher:🧩 Foundation URL networking
Set of helpers for building API clients based on the native Foundation‘s networking.
urlEndpoint
function creates anEndpoint
that uses Foundation’s networking:URLRequestFactory<Request>
is a generic function that transforms someRequest
intoURLRequest
, optionally throwing an error:URLResponsePublisherFactory
is a function that transformsURLRequest
intoURLResponsePublisher
:Convenience extension allows to use
URLSession
as aURLResponsePublisherFactory
:URLResponsePublisher
is a combine publisher emitting network responses or failing with networking error:URLResponseValidator
is a function that validates responseData
andURLResponse
, optionally throwing validation error:URLResponseDecoder<Response>
is a generic function that transforms responseData
andURLResponse
into someResponse
, optionally throwing decoding error:🧰 Installation
SwiftEndpoint is compatible with Swift Package Manager. You can add it as a dependency to your Xcode project or swift package.
🛠 Development
Running tests:
Developing in Xcode:
☕️ Do you like the project?
📄 License
Copyright © 2020 Dariusz Rybicki Darrarski
License: GNU GPLv3