I want to cache some response data for urls, and get cached data by url. But I use a TargetType value to make a request, and I don't find an easy way to get absolute url from this value.
@ufosky Can you use TargetType's two propertiesbaseURL & path to form the absolute URL? You could add an extension to TargetType to make this easier for you across all of your targets.
I just remembered that Moya also has a URL extension to initlaize a URL with a TargetType. You can check out the source file for this. It could help 馃槂
But this way only get url from baseURL & path, if some parameters in the url, like http://www.example.com/path?param1=test, only get result http://www.example.com/path
Sorry @ufosky you're right. I'm not sure of any easy way of doing this at the moment. The final URLRequest is constructed through the Endpoint class 馃
I use this code currently:
if let request = try? MoyaProvider.defaultEndpointMapping(for: target).urlRequest(),
let url = request.url {
let key = url.absoluteString
return key
}
And you could extend your TargetType maybe to wrap this in a variable 馃憤
Sent with GitHawk
happy we could help @ufosky!
Most helpful comment
I use this code currently: