DanielCardonaRojas / APIClient

A lightweight networking client abstraction over URLSession
MIT License
6 stars 0 forks source link

MockDataClientHijacker can not intercept transformed Endpoints #7

Open DanielCardonaRojas opened 3 years ago

DanielCardonaRojas commented 3 years ago

Suppose we have a model that collects information from 2 different endpoints

struct Products {
     let title: String
     var descriptions: [Description]?
}

This would be done by chaining 2 request something like Endpoint followed by Endpoint<[Description]> and adding the result from the second request to the product.

This can be done by mapping the Endpoint to Endpoint which would go something like this:

descriptionsEndpoint.map { descriptions in 
    var product = fetchedProduct // Captured from context
    product.descriptions = descriptions
    return product
}

As the type of the descriptions endpoint is lost, when intercepting with the clientHijacker which uses the expected response as part of the information to determine if should hijack or not, there is no actual interception occurring.

Ideas

Make Config type more relaxed so that typeString property is options and make it so that in this cases a more complete description of the request is supplied e.g (path and method)

DanielCardonaRojas commented 3 years ago

Could be cool to try out a phantom type for Config.

DanielCardonaRojas commented 3 years ago

Defer returning data from hijacker to Endpoint decoding closure.

DanielCardonaRojas commented 3 years ago

Looks like the previous approach won't work, instead maybe removing map from Endpoint api and reimplement chain in APIClientPublisher.