Simpler api endpoints are now integrated into the MainViewModel

This commit is contained in:
Vicnet
2023-11-16 17:53:30 +01:00
parent 3563c23e29
commit 23e1a665df
13 changed files with 284 additions and 74 deletions

View File

@@ -40,8 +40,9 @@ struct ApiRequest {
Logger.network.debug("\(method.rawValue) \(path) sending ...")
// Prepare URL
let urlString = serverAddress + cookbookPath + path
Logger.network.debug("Full path: \(urlString)")
let urlString = "https://" + serverAddress + cookbookPath + path
print("Full path: \(urlString)")
//Logger.network.debug("Full path: \(urlString)")
guard let urlStringSanitized = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return (nil, .unknownError) }
guard let url = URL(string: urlStringSanitized) else { return (nil, .unknownError) }
@@ -76,6 +77,9 @@ struct ApiRequest {
do {
(data, response) = try await URLSession.shared.data(for: request)
Logger.network.debug("\(method.rawValue) \(path) SUCCESS!")
if let data = data {
print(data, String(data: data, encoding: .utf8))
}
return (data, nil)
} catch {
let error = decodeURLResponse(response: response as? HTTPURLResponse)