apple / swift-openapi-urlsession

URLSession transport for Swift OpenAPI Generator.
https://swiftpackageindex.com/apple/swift-openapi-urlsession/documentation
Apache License 2.0
160 stars 33 forks source link

Background upload / download using URLSession transport #54

Open hivenet-erwanjestin opened 1 year ago

hivenet-erwanjestin commented 1 year ago

We are heavily using openapi to generate our REST library. In this library we do files upload and download.

Everything works pretty well but now we want to allow background requests. That means we need to use an URLSession with URLSessionConfiguration.background().

I saw we could override the URLSession but the most challenging part is we need a dedicate delegate for each API we have running in the background.

What's the best way to manage that with an openapi generated library? For now, we are considering doing it manually, so removing this library from our code :'(

czechboy0 commented 1 year ago

Hi @hivenet-erwanjestin,

I think it should be possible to make this work with the generated client. I can't offer much support on using background tasks with URLSession, but how you can proceed:

After you have it working, you could contribute your changes back to https://github.com/apple/swift-openapi-urlsession so that it also works for others using background tasks.

But you should be able to use the generator in this repo, and the runtime library without any modifications, all the changes should be isolated to the URLSession transport.

mooshee commented 2 months ago

+1 would be nice to have background support

guoye-zhang commented 2 months ago

This is somewhat tricky since background sessions work with files instead of data streams. The code needs to be changed to upload a file or download a file, and per-task delegate is not available with background sessions.

czechboy0 commented 2 months ago

Good points. Yeah I imagine that if background tasks are to be supported here, we need a proposed design of how it'd all work. Let's just use this issue to track any progress on that, ideally driven by someone who has a use case here.