async-http-client
async-http-client copied to clipboard
offer Structured Concurrency API that supports HTTP response streaming
Currently, most of HTTPClient's API surface only supports Structured Concurrency violating functions. Baby steps to rectify this have been done in #806. But the elephant in the room is of course the unstructured HTTP request API.
We need to also provide a
try await httpClient.execute(request) { status, responseBodyStream in
...
}
API that fulfils Structured Concurrency by supporting cancellation and tearing everything down when the body function returns or throws without ineffective and ugly hacks like deinit (which still violates Structured Concurrency because it doesn't follow the structure of the code).
I think we need slightly more since request can also be streamed and AsyncSequence is not enough for that. I'm thinking gRPC got it right here:
swift
try await httpClient.execute { requestWriter in
try await requestWriter.write()
return [:] // trailers
} onResponse: { status, responseBodyStream, trailers in
print(status)
for try await responseData in responseBodyStream { ... }
try await trailers.value()
}
I think we need slightly more since request can also be streamed and
AsyncSequenceis not enough for that.
Possibly, but currently we do need an AsyncSequence<BB>, right? So this is will legal
try await httpClient.post("https://foo.com", body: myAsyncSequence)
Don't need any with* stuff here.
I think we need slightly more since request can also be streamed and
AsyncSequenceis not enough for that.Possibly, but currently we do need an
AsyncSequence<BB>, right? So this is will legaltry await httpClient.post("https://foo.com", body: myAsyncSequence)Don't need any
with*stuff here.
Yes if we just wrap the current AHC APIs than this is enough. In general this API should always be legal it is just a convenience on top of the bi-di streaming API with a writer.
Yes if we just wrap the current AHC APIs than this is enough. In general this API should always be legal it is just a convenience on top of the bi-di streaming API with a writer.
Gotcha, yes. So I think there are (at least) two parts to this:
- For any existing AHC API offer one that does the same but adds Structured Concurrency
- Offer other, more general APIs
I was thinking (1) for this ticket and you added (2). That's fine, I'm happy with this, just to check we're on the same page.