I'm trying to access from SwiftUI to an external API that has basic authentication, but I can't figure out how to do it. I have connected to other APIs without authentication and everything works correctly. How could you modify the following code to be able to use the API with basic authentication? Thanks for the help
func loadData() async {
guard let url = URL(string: "https://urlapi/user/basicauth") else {
print("bad URL")
return
}
do {
let (data, _) = try await URLSession.shared.data(from: url)
users = try JSONDecoder().decode([JSONuser].self, from: data)
} catch {
print(error)
}
}