Connect to 3rd party REST API with a reusable pool of clients

I'm new to NIO/Vapor, trying to understand what the common patterns are for doing certain things.

So for example I build a server that makes frequent requests to 3rd party REST services. Something suggests having some kind of a reusable pool of HTTP clients might be helpful, instead of creating client objects every time with every request.

Are there any solutions out of the box or close to it in Vapor or NIO? Or should I build my own pool functionality, based on some threading primitives?

2 Likes

The Swift NIO HTTP Client doesn't implement pooling yet but this improvement is on the list of features the community would love to see implemented.

I opened an issue for this and also started a draft PR. Don't hesitate to give feedback!

There is also a thread on the forums about this client.

1 Like

Doesn't Client included with Vapor already do this? Check out request.client() (or really Container.client()).

Yup, using req.client() will share the same Client object (per event loop).