fastify-http-client
A plugin for Fastify that adds support for sending HTTP(s) requests.
Under the hood urllib is used, the options passed to register
will be used as the default arguments while creating the urllib client.
Install
npm i fastify-http-client --save
Usage
Just add it to the project generated via fastify-cli with register
in app.js
as below.
You can access the urllib HttpClient
instance via fastify.httpclient
, which can be used to send HTTP(s) requests via methods curl
/ request
/ requestWithCallback
/ requestThunk
. You can also send HTTP(s) requests directly via fastify.curl
, which is the same function as request
/ curl
in urllib.
'use strict' module { fastify // request via httpclient fastifyhttpclient // request via curl method fastify }
You may also supply an existing urllib HttpClient
instance by passing an options object with the client property set to the instance.
'use strict' const urllib = module { fastify // ... }
Options
Besides client
property sampled above, properties listed in urllib / API Doc / Method / Arguments are all supported in the options object passed to register
.
License
Licensed under MIT.