This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func fetch() async throws { | |
// prepare the request and execute it | |
let task = try await request.urlSessionTask(inClient: client) | |
let response = try await fetch(request, task: sessionTask: task) | |
// ask to validator the action to perform on this request | |
let action = client.validate(response: response, forRequest: request) | |
switch action { | |
case .failChain(let error): | |
return HTTPResponse(error: error) // fail with error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let loggedUser = try await login.fetch(User.self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let result: HTTPResponse = try await req.fetch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myObject = ... | |
req.body = .json(myObject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
req.body = .multipart(boundary: nil, { | |
$0.add(string: "value", name: "param_1") | |
$0.add(fileURL: fileURL, name: "image", mimeType: .gif) | |
$0.add(string: "some other", name: "param_2") | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
req.headers[.contentType] = .bmp | |
req.headers = .init([ | |
.contentType: .bmp | |
"X-Custom-Header": "abc" | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let req = HTTPRequest { | |
$0.url = URL(string: "https://.../login")! | |
$0.method = .post | |
$0.timeout = 15 | |
$0.redirectMode = redirect | |
$0.maxRetries = 4 | |
$0.headers = HTTPHeaders([ | |
.init(name: .userAgent, value: myAgent), | |
.init(name: "X-API-Experimental", value: "true") | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let todo = try await HTTPRequest("https://jsonplaceholder.typicode.com/todos/1") | |
.fetch(Todo.self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FFService { | |
// ... | |
private var flagsController: FlagsBrowserController | |
func showFlagsBrowser() { | |
flagsController = .create(loaders: [user, ...]) | |
mainController.present(flagsController, animated: true, completion: nil) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserExperiments: FlagCollectionProtocol { | |
@Flag(default: false, computedValue: MiscFlags.computedRememberLogin) | |
var rememberLogin: Bool | |
private static func computedRememberLogin() -> Bool? { | |
Language.main.code == "it" && allowsSSON == true | |
} | |
... |