Swiftpack.co -  michzio/Networking as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
michzio/Networking
Simple URLSession-based Networking library that enables to use Combine publishers
.package(url: "https://github.com/michzio/Networking.git", from: "0.0.4")

Networking

An example implementation of Router

enum Router: IRouter {
    
    case sample
    case uploadFile
    
    static var baseURL: String = "https://mockapi.com"
    
    var path: String {
        switch self {
        case .sample:
            return "/sample"
        case .uploadFile:
            return "/upload"
       
        }
    }
    
    var isFullPath: Bool { false }
    
    var method: HTTPMethod {
        switch self {
        case .sample:
            return .get
        case .uploadFile:
            return .post
        }
    }
    
    var headerParams: [String : String] { [:] }
    
    var authorization: Authorization { 
    
        switch self {
        case .sample:
            return .noAuth
        case .uploadFile:
            return .queryParams(["apikey": "#apikey"])
        }
    }
    
    var queryParams: [String : Any] { [:] }
    
    var bodyParams: [String : Any] { [:] }
    
    var bodyEncoding: EncodingType {
        
        switch self {
        case .uploadFile:
            return .multipart(boundary: "boundary")
        default:
            return .formData
        }
    }
    
    var files: [FileUploadInfo]? {
        
        switch self {
        case .uploadFile:
            if let file = Self.mockUploadFile {
                return [file]
            }
            return nil
        default:
            return nil
        }
    }
    
    static var mockUploadFile: FileUploadInfo? = nil
}

An example implementation of BaseService

import Networking

protocol IProfileService {
    
    func getProfile() -> AnyPublisher<ProfileDTO, Error>
}

class ProfileService: BaseService<JSONDecoder>, IProfileService {
   
    
    func getProfile() -> AnyPublisher<ProfileDTO, Error> {
        
        request(Router.profile)
    }
}

GitHub

link
Stars: 0
Last commit: 3 weeks 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.

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