#How to use Gaxios as client HTTP library?

6 messages · Page 1 of 1 (latest)

rich gorge
#

Is there information on how to use Gaxios (or any other) as client HTTP library?

Unfortunately, HttpModule (@nestj/axios) leaks lots of abstractions and is tight coupled to Axios, which I want to avoid due to their lousy error stack traces. I'd appreciate some orientation about doing this the NestJs way.

shut knoll
#

You could import the package directly and use it like you would any other node project, or you could create a custom provider for the package and inject it, similar to how Nest does with @nestjs/axios

rich gorge
#

hey @shut knoll , as HttpModule sounds quite generic, I expected this would be the preferred way to have an HTTP client available to NestJs apps and that there would be some way to inject an underlying implementation into it. As it looks to me, it's more of an AxiosModule, which is ok, but not what I was looking for. Thank you for the information!

shut knoll
#

If you'd look, @nestjs/axios is only an axios wrapper. Yes, it was, and is, called HttpModule, inspired by Angular's approach, and generally you'd only have one http client in the application anyways, so the naming made sense. It sed to be bundled in with @nestjs/common but was split out in v9 to make @nestjs/axios so it was more clear that it is specifcally for axios

#

You can absolutely use whatever http client you want, nest just provides an existing integration with axios, which, as you're not happy with, you don't have to use

#

Side note, the HttpModule was originally inspired by Angular's HttpModule, which, to my knowledge, also didn't provide as way to swap http clients