Registry / devops / egg-axios

egg-axios

JSON →
library1.1.6jsnpmunverified

A plugin for integrating Axios into Egg.js applications. Version 1.1.6 wraps Axios to provide a convenient `ctx.http` API for making HTTP requests within Egg.js context. It supports GET, POST, and other methods with built-in URL parameter handling (e.g., `/user/:id`). The plugin is minimal and relies on Axios's documentation for full feature details. It has not been updated recently and is suitable for simple integrations, but lacks TypeScript typings and modern ESM support.

npm install egg-axios
INSTALL
IMPORT
SIG · EGG-AXIOS
E
egg-axios
devopsjavascriptv1.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

http
// No import needed; accessed via ctx.http in Egg controller/service
import axios from 'egg-axios'
egg-axios is a plugin, not a module. It exposes `ctx.http` after enabling in plugin.js.
example
// config/plugin.js exports.http = { enable: true, package: 'egg-axios' }
// Trying to require/import the package in code
The plugin must be configured in plugin.js, not imported directly.
Config
// config/config.default.js exports.http = { headers: {'Content-Type': 'application/json'}, timeout: 10000 }
// Setting config under wrong key or using module.exports incorrectly
Configuration is placed under `exports.http` in config files, matching the plugin name.

Shows a full Egg.js setup: enabling the plugin, configuring default headers and timeout, and using ctx.http.get in a controller with error handling.

// config/plugin.js 'use strict'; /** @type Egg.EggPlugin */ module.exports = { http: { enable: true, package: 'egg-axios', }, }; // config/config.default.js exports.http = { timeout: 5000, headers: { common: { 'Content-Type': 'application/json;charset=UTF-8', }, }, }; // app/controller/home.js class HomeController extends Controller { async index() { const ctx = this.ctx; try { const data = await ctx.http.get('https://api.example.com/users', { id: 1 }); ctx.body = data; } catch (e) { ctx.status = 500; ctx.body = e.message; } } } module.exports = HomeController;
Debug
Known issues
gotchaThe plugin is unmaintained and may not support the latest Axios versions.
fix
Consider using a more active Egg.js HTTP plugin like egg-axios-plus or implement Axios manually in a service.
affects: >=1.0.0
gotchaThe plugin only returns response data, not the full Axios response object (e.g., headers, status).
fix
If you need full response details, use Axios directly instead of this plugin.
affects: >=1.0.0
breakingDoes not provide TypeScript type definitions, causing type errors in TS projects.
fix
Define custom types or use a plugin that includes types.
affects: >=1.0.0
deprecatedAxios v1.x may have breaking changes not reflected in this plugin.
fix
Pin Axios version to v0.x if using this plugin, or upgrade to a maintained alternative.
affects: >=1.1.0
gotchaThe plugin does not support Axios interceptor configuration via Egg config – you may need to configure interceptors in a custom service.
fix
Create a wrapper service that configures an Axios instance with interceptors yourself.
affects: >=1.0.0
Errors
Common errors & fixes
ctx.http is not a function
Plugin not enabled in config/plugin.js
fix
Add `http: { enable: true, package: 'egg-axios' }` to config/plugin.js
Cannot find module 'egg-axios'
Package not installed or plugin configuration missing
fix
Run `npm install egg-axios --save` and ensure plugin is correctly configured
exports.http is not a function
Trying to call ctx.http() directly instead of ctx.http.get/post/etc.
fix
Use `await ctx.http.get(url, params)` or `await ctx.http.post(url, data)`
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies
eggrequiredCore framework required for plugin to work
axiosrequiredHTTP client library used internally
Agent activity
4 hits · last 30 days
node
4
Resources
egg-axios — npm install egg-axios · libregistry