SSeoNetwork 1.0.0

SSeoNetwork 1.0.0

Maintained by Son Nguyen.



  • By
  • Son Nguyen

SSeoNetwork

SSeoNetwork is an un-opinionated network framework with only the minimal functionalities and no bloater. Use this library if you only need to make only a few API calls and nothing else as this library doesn't offer much other than that :)

SSeoNetwork does provide in-memory cache capability. It also buffers pending requests, meaning if a request is waiting for the response and SSNetwork receives another identical request, it will not send the subsequent request but simply waits for the reponse from the first one and returns it to all pending identical requests.
SSeoNetwork doesn't use regular callback, it only supports Combine.

Sample usage.

Create a request class

You can either use the SSNetworkRequest class directly or create a subclass to encapsulate details of the requrest. In the example below, I choose to subclass SSNetworkRequest.

class SampleRequest: SSNetworkRequest<DataModel> {
    
    init() {
        super.init(baseUrl: baseUrl, path: ["version", "sample", "path"], method: .GET)
        addQuery(key: key1, value: value1)
        addQuery(key: key2, value: value2)
        // or setQuery([key1: value1, key2: value2])
        setAuthToken(token)
        // or setApiKey(key, name: yourKeyName)
        setCacheDuration(120) // in seconds
    }
}

Call the API

let request = SampleRequest()
SSNetworkManager.shared.makeServiceCall(forRequest: request)
    .sink { (_) in
        // remove the sub that SSNetworkManager has been keeping for you
        SSNetworkManager.shared.unregisterSubscriber(forRequest: request)
    } receiveValue: { [weak self] (user) in
        self?.otherUser = user
    }
    .store(in &yourDisposeBag)