{"id":13403736,"url":"https://github.com/davidedantonio/fastify-axios","last_synced_at":"2025-04-06T04:07:29.579Z","repository":{"id":40234498,"uuid":"212508555","full_name":"davidedantonio/fastify-axios","owner":"davidedantonio","description":"Add axios http client to your fastify instance","archived":false,"fork":false,"pushed_at":"2025-03-24T07:43:04.000Z","size":1357,"stargazers_count":41,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T17:52:14.473Z","etag":null,"topics":["axios","axios-plugin","fastify","fastify-plugin","nodejs","nodejs-library","nodejs-modules"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidedantonio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-03T06:10:56.000Z","updated_at":"2025-01-27T00:35:08.000Z","dependencies_parsed_at":"2023-12-27T21:13:21.282Z","dependency_job_id":"94821c18-862f-4b68-a328-907fd4c6cb8f","html_url":"https://github.com/davidedantonio/fastify-axios","commit_stats":{"total_commits":69,"total_committers":4,"mean_commits":17.25,"dds":"0.30434782608695654","last_synced_commit":"695c332cf26103d439cad5fd34a98238c989c05a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Ffastify-axios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Ffastify-axios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Ffastify-axios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidedantonio%2Ffastify-axios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidedantonio","download_url":"https://codeload.github.com/davidedantonio/fastify-axios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430866,"owners_count":20937874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","axios-plugin","fastify","fastify-plugin","nodejs","nodejs-library","nodejs-modules"],"created_at":"2024-07-30T19:01:33.898Z","updated_at":"2025-04-06T04:07:29.550Z","avatar_url":"https://github.com/davidedantonio.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fastify-axios\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![codecov](https://codecov.io/gh/davidedantonio/fastify-axios/branch/master/graph/badge.svg)](https://codecov.io/gh/davidedantonio/fastify-axios)\n\nA plugin for Fastify that adds support for sending requests via [`axios`](https://github.com/axios/axios), a promise based HTTP(s) client for node.js and browser.\n\nUnder 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.\n\n## Install\n\n```\nnpm install fastify-axios\n```\n\n## Default usage\n\nJust add it to the project generated via [`fastify-cli`](https://github.com/fastify/fastify-cli) or with `register` in you application as below.\n\nYou 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\n\n```javascript\n\"use strict\";\n\nmodule.exports = async function (fastify, opts) {\n  fastify.register(require(\"fastify-axios\"));\n\n  // request via axios.get\n  const { data, status } = await fastify.axios.get(\"https://nodejs.org/en/\");\n  console.log(\"body size: %d\", data.length);\n  console.log(\"status: %d\", status);\n};\n```\n\nAlternatively you can specify default args to your axios instance. You can take a look at the default parameters here [https://github.com/axios/axios](https://github.com/axios/axios#request-config):\n\n```javascript\n\"use strict\";\n\nmodule.exports = async function (fastify, opts) {\n  fastify.register(require(\"fastify-axios\"), {\n    baseURL: \"https://nodejs.org\",\n  });\n\n  // request via axios.get to https://nodejs.org/en/\n  const { data, status } = await fastify.axios.get(\"/en/\");\n  console.log(\"body size: %d\", data.length);\n  console.log(\"status: %d\", status);\n};\n```\n\n## Add more clients\n\nIt's possibile to add more than one `axios` client to your fastify instance. Here's how:\n\n```javascript\n\"use strict\";\n\nmodule.exports = async function (fastify, opts) {\n  fastify.register(require(\"fastify-axios\"), {\n    clients: {\n      v1: {\n        baseURL: \"https://v1.api.com\",\n        headers: {\n          Authorization: \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJxyz\",\n        },\n      },\n      v2: {\n        baseURL: \"https://v2.api.com\",\n        headers: {\n          Authorization: \"Bearer UtOkO3UI9lPY1h3h9ygTn8pD0Va2pFDcWCNbSKlf2HE\",\n        },\n      },\n    },\n  });\n\n  // Now you can use the apis in the following way\n  const { dataV1, statusV1 } = await fastify.axios.v1.get(\"/ping\");\n  const { dataV2, statusV2 } = await fastify.axios.v2.get(\"/ping\");\n\n  // do something with dataV1 and dataV2\n};\n```\n\n## License\n\nLicensed under [MIT](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedantonio%2Ffastify-axios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidedantonio%2Ffastify-axios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidedantonio%2Ffastify-axios/lists"}