Which Framework/Package to use for Swift Linux that also can be used for Vapor

Viewed 101

I've written an API-Wrapper for an external REST-API. This wrapper provides iOS and macOS-Apps an convenient access to that API. But I want to expand that API-Wrapper to Vapor on Linux. Linux (RaspiOS with 64-Bit) has Swift 5.5 running (without swift-corelibs-foundation) so URLSession is not available. I tried SwiftyRequest and AsyncHTTPClient but both did not play well with Vapor. E.g. wait() can't be used with Vapor and whenComplete() draws error * underlying error: uncleanShutdown* while syncShutdown can't be used for the same reason as wait()

So I'm stuck with connecting to the API.

What would be a proper way to perform the request that works standalone and with vapor?

1 Answers

Vapor has a Client protocol you should use if using Vapor but that's built on top of AsyncHTTPClient. You're correct in that you can't use wait() if you're on an event loop but you should use future handlers (or even better the new async/await APIs). What part is reporting unclean shutdown? If that's coming from AsyncHTTPClient then the API you're calling isn't closing the connection properly but you can configure it to ignore this.

As an aside, Vapor requires Foundation so you'll need that to be able to build it anyway

Related