Closed davidgoli closed 8 years ago
Nice idea. I think the best way to implement such a thing would be to create hooks, as you mentioned. This allows you to add any kind of functionality that depends on network activity. Perhaps we can add a delegate to the standard HTTPClient. Custom NetworkClients can implement delegates or hooks themselves.
What do you think about the following:
public protocol NetworkClientDelegate {
func networkClient(client: NetworkClient, willPerformRequestWithMethod: String, URL: NSURL, payload: NSData?)
func networkClient(client: NetworkClient, didPerformRequestWithMethod: String, URL: NSURL, success: Bool)
}
I've added a HTTPClientDelegate protocol to the built in HTTPClient. You can use this to implement such functionality. Custom NetworkClients can incorporate their own delegate protocol.
Sounds great, thank you!
This is a nice-to-have. Currently we can explicitly call
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
before/after each request, but that becomes cumbersome and clutters the codebase with boilerplate. The preferred option is to just provide a boolean to toggle this behavior on/off globally for theSpine
instance or theHTTPClient
instance. Another option is to provide a hook inHTTPClient
for request began/ended so that we could implement this ourselves and/or possibly other behaviors around network activity.