Background upload / download using URLSession transport
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 :'(
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:
- fork the URLSession transport repo only: https://github.com/apple/swift-openapi-urlsession
- provide the forked version to your
Client(...)initializer - see what changes you need to make to make background tasks work
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.
+1 would be nice to have background support
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.
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.
What exactly do you need from a use-case perspective? We need to support large background image and video uploads from a file.