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?

1 Like

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
(MTV) #3

This is what you may be looking for

(Benjamin Mayo) #4

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

(Tanner) #5

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