https://restcountries.eu/rest/v1/name/Germany?fullText=true
→ GET
→ https://restcountries.eu/rest/v1
→ name/Germany
→ fullText=true
Slide 13
Slide 13 text
enum Method: String {
case GET = "GET"
...
}
protocol Resource {
var method: Method { get }
var path: String { get }
var parameters: [String: String] { get }
}
typealias Border = (name: String, nativeName: String)
class BordersViewModel {
let borders: Observable<[Border]>
...
}
Slide 49
Slide 49 text
self.borders = client.countryWithName(countryName)
// Get the countries corresponding to the alpha codes
// specified in the `borders` property
.flatMap { country in
client.countriesWithCodes(country.borders)
}
// Catch any error and print it in the console
.catchError { error in
print("Error: \(error)")
return Observable.just([])
}
// Transform the resulting countries into [Border]
.map { countries in
countries.map { (name: $0.name, nativeName: $0.nativeName) }
}
// Make sure events are delivered in the main thread
.observeOn(MainScheduler.instance)
// Make sure multiple subscriptions share the side effects
.shareReplay(1)