
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
fastify-axios
Advanced tools
A plugin for Fastify that adds support for sending requests via axios
, a promise based HTTP(s) client for node.js and browser.
Under the hood axios
http client is used, the options passed to register will be used as the default arguments while creating the axios http client.
npm install fastify-axios
Just add it to the project generated via fastify-cli
or with register
in you application as below.
You can access the axios
instance via fastify.axios, which can be used to send HTTP(s) requests via methods GET
, POST
, PUT
, DELETE
etc. Here a simple example
"use strict";
module.exports = async function (fastify, opts) {
fastify.register(require("fastify-axios"));
// request via axios.get
const { data, status } = await fastify.axios.get("https://nodejs.org/en/");
console.log("body size: %d", data.length);
console.log("status: %d", status);
};
Alternatively you can specify default args to your axios instance. You can take a look at the default parameters here https://github.com/axios/axios:
"use strict";
module.exports = async function (fastify, opts) {
fastify.register(require("fastify-axios"), {
baseURL: "https://nodejs.org",
});
// request via axios.get to https://nodejs.org/en/
const { data, status } = await fastify.axios.get("/en/");
console.log("body size: %d", data.length);
console.log("status: %d", status);
};
It's possibile to add more than one axios
client to your fastify instance. Here's how:
"use strict";
module.exports = async function (fastify, opts) {
fastify.register(require("fastify-axios"), {
clients: {
v1: {
baseURL: "https://v1.api.com",
headers: {
Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJxyz",
},
},
v2: {
baseURL: "https://v2.api.com",
headers: {
Authorization: "Bearer UtOkO3UI9lPY1h3h9ygTn8pD0Va2pFDcWCNbSKlf2HE",
},
},
},
});
// Now you can use the apis in the following way
const { dataV1, statusV1 } = await fastify.axios.v1.get("/ping");
const { dataV2, statusV2 } = await fastify.axios.v2.get("/ping");
// do something with dataV1 and dataV2
};
Licensed under MIT
FAQs
Decorate fastify instance with axios http client
The npm package fastify-axios receives a total of 1,254 weekly downloads. As such, fastify-axios popularity was classified as popular.
We found that fastify-axios demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.