Swiftpack.co - brmaciel/NetworkKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by brmaciel.
brmaciel/NetworkKit 1.0.0
NetworkKit is an HTTP networking library and is available to be used in any swift project.
⭐️ 1
🕓 30 weeks ago
.package(url: "https://github.com/brmaciel/NetworkKit.git", from: "1.0.0")

NetworkKit

NetworkKit is an HTTP networking library.

Components

Request

  • RequestProtocol: this protocol has all parameters needed to be used to build the request.
  • HTTPMethod: enumeration that provides all http methods available.

NetworkResponse

  • NetworkResponse: this protocol has all information about the network response.
  • NetworkResponseResult: enumeration with possible network request results (success, failure).
  • NetworkResponseError: enumeration with possible network request errors. It is used to compose the network response result when it is a failure.

ResponseMapper

  • ResponseMapper: protocol that defines a response mapper. Response mappers are responsible for mapping a response instance (which is decoded from Data) into some model.
  • MainResponseMapper: a concrete class that implements the protocol. It must be inherited and its method .map(_:) should always be overriden.

Service

  • ServiceProtocol: protocol that defines methods that should be implemented by a worker.
  • MainWorker: it's the main worker and responsible for all requests. It must be inherited and its subclasses should use one of its final methods to make requests and treat the response.
// Example
class ExampleWorker: MainWorker {
    func fetchExample() {
        makeRequest(request: ExampleRequest(),
                    mapResponseAction: ExampleMapper().map,
                    success: { model in
                        print(model)
                    }, failure: { response in
                        print(response)
                    })
    }
}

Provider

  • BackendProvider: protocol that defines a backend provider. A backend provider is responsible for the receiving request parameters, treat them and make the request using some ApiRequester.
  • DefaultBackendProvider: it's an example of backend provider with a default implementation of how to treat the request parameters (header, body, http method, endpoint, path parameters, query parameters), build the request url and make the request using the DefaultApiRequester. Feel free to inherit this class or create your own backend provider from scratch.

ApiRequester

  • ApiRequester: protocol that defines an api requester. The api requester is the actual component responsible for making the request and communicating to the api.
  • DefaultApiRequester: it's an example of api requester with a default implementation of making the request. Feel free to create your own api requester.

GitHub

link
Stars: 1
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Initial release
30 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics