-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simple GET fails with HTTPClientError.cancelled #477
Comments
Hey Mark, To fix this, you need to wait before you call If you just want to quickly experiment with the Furthermore, if you only want to do HTTP requests on Apple platforms (iOS, macOS etc.) you actually do not need to use |
Thanks so much for clarifying that! I have fixed my code in the GitHub repo referenced above in case others want to see a working version. You mentioned that I can use URLSession to send the HTTP request. The reason I reached for AsyncHTTPClient is that I was looking for a simpler API for making REST calls. It does seem simpler, but I was hoping for something along the lines of JavaScript's Fetch API. I know this is a matter of opinion, but do you think most Swift developers use URLSession directly for REST calls and don't mind how much code is required to use it? |
I just learned how to use async/await with URLSession and I like the code MUCH better now! |
New repo for my demo code: https://github.com/mvolkmann/SwiftUI-Async-URLSession/blob/main/SwiftUI-Async-URLSession/ViewModel.swift |
I highly recommend you async/await is not yet supported by |
I'm trying this package with a simple GET request to a local URL, but I get
failure(HTTPClientError.cancelled)
.Pasting the same URL in a web browser works.
I am sending the request from an
init
method in a ViewModel class. Should this work?You can see my very basic code here:
https://github.com/mvolkmann/SwiftUI-AsyncHTTPClient/blob/main/SwiftUI-AsyncHTTPClient/ViewModel.swift
An instance of ViewModel is created in
ContentView.swift
which is here:https://github.com/mvolkmann/SwiftUI-AsyncHTTPClient/blob/main/SwiftUI-AsyncHTTPClient/ContentView.swift
The text was updated successfully, but these errors were encountered: