Skip to content

darrarski/SwiftEndpoint

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

πŸ“¦ SwiftEndpoint

Swift v5.1 Swift Package Manager platforms iOS macOS

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 some Request into some Response publisher:

typealias Endpoint<Request, Response> = (Request) -> AnyPublisher<Response, Error>

🧩 Foundation URL networking

Set of helpers for building API clients based on the native Foundation's networking.

urlEndpoint function creates an Endpoint that uses Foundation's networking:

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:

typealias URLRequestFactory<Request> = (Request) throws -> URLRequest

URLResponsePublisherFactory is a function that transforms URLRequest into URLResponsePublisher:

typealias URLResponsePublisherFactory = (URLRequest) -> URLResponsePublisher

Convenience extension allows to use URLSession as a URLResponsePublisherFactory:

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:

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:

typealias URLResponseDecoder<Response> = (Data, URLResponse) throws -> Response

🧰 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:

swift test

Developing in Xcode:

swift package generate-xcodeproj
open -a SwiftEndpoint.xcodeproj

β˜•οΈ Do you like the project?

Buy Me A Coffee

πŸ“„ License

Copyright Β© 2020 Dariusz Rybicki Darrarski

License: GNU GPLv3

About

Lightweight library providing higher level of abstraction for implementing networking in iOS and macOS applications

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages