Swiftpack.co - SergeMaslyakov/Network-iOS as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Network framework for iOS
.package(url: "https://github.com/SergeMaslyakov/Network-iOS.git", from: "v1.2")

Network-iOS framework

No dendencies, just a plain URLSession

Swift 5+


  1. as carthage dependency: add in cartfile github "SergeMaslyakov/Network-iOS"
  2. as submodule in the project: to add in your workspace as a sub-project

How to:

1 - Create an instance of NetworkClient, smth like that

let configuration = NetworkLayer.Configuration(timeout: 10,
                                               baseURL: "https://github.com",
                                               sessionDelegate: sessionDelegateProvider,
                                               authProvider: DefaultAuthorizationProvider(),
                                               responseDecoder: JSONResponseDecoder(),
                                               requestEncoder: JSONResponseEncoder(),
                                               defaultBehaviors: [DebugBehavior(logger: logger)])

let networkClient = NetworkClientImpl(configuration: configuration, 
                                      sessionConfiguration: config.sessionConfiguration)

2 - API Endpoint descriptors, e.g.

struct SignUpEndpoint: EndpointDescriptor {

    private let data: SignUpDataModel
    private let encoder = WWWFormRequestEncoder()

    init(data: SignUpDataModel) {
        self.data = data

    // MARK: - EndpointDescriptor

    let path: String = "auth/sign_up"
    let method: HTTPMethod = .post

    var headers: HTTPHeaders {
        return ["Content-Type": "application/x-www-form-urlencoded"]

    var customEncoder: NetworkRequestEncoding? {
        return encoder

    var params: [String: Any]? {
        return data.toJSON()

    var authRequired: Bool {
        return false


3 - Send request (generic or plain request)

let endpoint = SignUpEndpoint(data: data)
var task: URLSessionDataTask?

let completion: ((Result<T, NetworkError>) -> Void) = { result in
    switch result {
    case .success(let model):
        // do smth with model
    case .failure(let error):
        // do smth with error

do {
    task = try networkClient.sendRequest(endpoint: endpoint, completion: completion)
} catch {
    // catch validation, coding errors


Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

1 week ago

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