Registry / devops / axios-adapter-uniapp

axios-adapter-uniapp

JSON →
library0.1.4jsnpmunverified

An Axios adapter for uni-app that bridges Axios HTTP client with uni-app's `uni.request` and `uni.uploadFile` APIs, enabling developers to use Axios-style request configuration and interceptors within uni-app projects. Current version 0.1.4 is stable with low release cadence. Key differentiators: seamless integration with Axios ecosystem (interceptors, CancelToken), support for GET/POST and file uploads via `uni.uploadFile`, and compatibility with Axios' cancellation pattern.

npm install axios-adapter-uniapp
INSTALL
IMPORT
SIG · AXIOS-ADAPTER-UNIA
A
axios-adapter-uniapp
devopsjavascriptv0.1.4
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.

default
import axiosAdapterUniapp from 'axios-adapter-uniapp'
const axiosAdapterUniapp = require('axios-adapter-uniapp')
Default import is the only export; CommonJS require works but is not recommended for ESM projects.
null (used as adapter config)
const instance = axios.create({ baseURL: '...', adapter: axiosAdapterUniapp })
const instance = axios.create({ baseURL: '...', adapter: 'axios-adapter-uniapp' })
The adapter must be the imported function, not a string.

Shows how to import, configure, and use axios-adapter-uniapp for GET and file upload requests in a uni-app environment.

import axios from 'axios'; import axiosAdapterUniapp from 'axios-adapter-uniapp'; const instance = axios.create({ baseURL: 'https://api.example.com', adapter: axiosAdapterUniapp }); // GET request with data (uni-app compatible) instance({ method: 'get', url: '/user', data: { id: 1 } }).then(response => { console.log(response.data); }).catch(error => { console.error(error); }); // POST request with file upload instance({ method: 'post', url: '/upload', filePath: '/storage/emulated/0/photo.jpg', name: 'file', formData: { description: 'A photo' } }).then(response => { console.log(response.data); });
Debug
Known issues
breakingThe adapter does not support all Axios features; only GET, POST, and file uploads are implemented. Other HTTP methods may not work as expected.
fix
Use only GET and POST methods. For file uploads, ensure config includes `filePath` and `name` or `files` array.
affects: >=0.1.0
gotchaCancelToken usage: uni-app does not natively support cancellation for `uni.request`/`uni.uploadFile`; this adapter simulates cancellation via Promise rejection but the underlying request may still complete.
fix
Handle cancellation in catch block with `axios.isCancel()`; be aware that the request might still be sent.
affects: >=0.1.0
deprecatedThe `data` field for GET requests is non-standard and may conflict with Axios expected behavior; it might be removed in future versions.
fix
Use `params` instead of `data` for GET requests to ensure compatibility with standard Axios.
affects: >=0.1.0
gotchaUpload via `files` array requires careful reference to uni-app documentation; multi-file upload behavior may differ from Axios expectations.
fix
Refer to uni-app `uni.uploadFile` documentation for correct file object structure (`{ name, uri }`).
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'axios-adapter-uniapp'
Package not installed or import path incorrect.
fix
Run `npm install axios-adapter-uniapp` and ensure the path in import statement is correct.
TypeError: adapter is not a function
Passing the package as a string instead of the imported function.
fix
Use `import axiosAdapterUniapp from 'axios-adapter-uniapp'` and then `adapter: axiosAdapterUniapp`.
Uncaught TypeError: Cannot read property 'request' of undefined
Axios not installed or not properly imported.
fix
Ensure axios is installed (`npm install axios`) and imported correctly.
Request failed with status code 0
Network error in uni-app environment (e.g., missing permissions, invalid URL).
fix
Check baseURL, ensure network permissions are granted, and use valid URLs.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
axiosrequiredThis package is an adapter for Axios and requires Axios to be installed as a peer dependency.
Agent activity
11 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
axios-adapter-uniapp — npm install axios-adapter-uniapp · libregistry