mirror of
https://github.com/zhigang1992/swift-request.git
synced 2026-01-12 22:52:42 +08:00
24 lines
534 B
Swift
24 lines
534 B
Swift
import Foundation
|
|
import SwiftRequest
|
|
|
|
let useAlamofire: Bool = Bool.random()
|
|
print("Using Alamofire: \(useAlamofire)")
|
|
|
|
let executor: any ServiceExecutor = if useAlamofire {
|
|
AlamofireServiceExecutor()
|
|
} else {
|
|
URLSessionServiceExecutor()
|
|
}
|
|
|
|
let service = QuoteServiceImpl(baseURL: "https://api.quotable.io", executor: executor)
|
|
|
|
do {
|
|
let quotes = try await service.getRandomQuotes(limit: 3)
|
|
print(quotes)
|
|
|
|
let quote = try await service.getQuote(by: "69Ldsxcdm-")
|
|
print(quote)
|
|
} catch {
|
|
print(error)
|
|
}
|