{"_id":"n-axios","_rev":"1-b47436ae0a7aef7d7cb3cda37e95c5f5","name":"n-axios","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"n-axios","version":"0.1.0","keywords":["request","axios","fetch","ajax"],"author":"","license":"ISC","_id":"n-axios@0.1.0","maintainers":[{"name":"dongdong.niu","email":"17621612284@163.com"}],"dist":{"shasum":"846d36649832f1938bee053a29a16a15bb245adc","tarball":"https://registry.npmjs.org/n-axios/-/n-axios-0.1.0.tgz","fileCount":11,"integrity":"sha512-LOWT2hS8/sjJ3EIO6/I/w94ycXPBduHd0cdAbjdwNnIu3ePsH4JgUOGkD5x+1bY6SThGezcplX4MeVg4FbyU9w==","signatures":[{"sig":"MEQCIBmtPt1zA6I11n8OYhgX09NQXCBa2mTfrU4Ujs1flXyAAiAypuUGSD9qiupx+EhNnvqz7qwmmAhLo03D+ZXnYsg62w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30556},"main":"./dist/index.cjs.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.esm.js","exports":{"import":"./dist/index.esm.js","require":"./dist/index.cjs.js"},"gitHead":"f64dca31cb4d15f1f5dd10bdb0a777d5d929be3a","scripts":{"push":"npm publish --access=public --registry=https://registry.npmjs.org","test":"echo \"Error: no test specified\" && exit 1","build":"rimraf dist && tsc && rollup -c rollup.config.js","debug":"npm run build:hot & npm run node:hot","node:hot":"nodemon example --watch ./example","build:hot":"rollup -c --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"dongdong.niu","email":"17621612284@163.com"},"repository":{"url":"","type":"git"},"_npmVersion":"8.1.2","description":"基于JS实现的前后端（browser and node）共用请求模块","directories":{},"_nodeVersion":"16.13.1","dependencies":{"axios":"^1.7.9"},"umdModuleName":"NAxios","_hasShrinkwrap":false,"devDependencies":{"tslib":"^2.6.3","rimraf":"^3.0.2","rollup":"^2.79.2","nodemon":"^3.1.9","typescript":"^5.7.2","@babel/core":"^7.17.9","@types/node":"^20.10.8","@babel/preset-env":"^7.16.11","@rollup/plugin-json":"^6.1.0","@rollup/plugin-alias":"^5.1.0","@rollup/plugin-babel":"^6.0.4","rollup-plugin-terser":"^7.0.2","@rollup/plugin-commonjs":"^25.0.8","@rollup/plugin-typescript":"^12.1.2","@rollup/plugin-node-resolve":"^15.2.3","rollup-plugin-polyfill-node":"^0.13.0","@babel/plugin-transform-runtime":"^7.17.0"},"_npmOperationalInternal":{"tmp":"tmp/n-axios_0.1.0_1739180676349_0.0010083687747080017","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"n-axios","version":"0.1.1","description":"基于JS实现的前后端（browser and node）共用请求模块","main":"./dist/index.cjs.js","types":"./dist/index.d.ts","module":"./dist/index.esm.js","type":"module","scripts":{"debug":"npm run build:hot & npm run node:hot","node:hot":"nodemon example --watch ./example","build:hot":"rollup -c --watch","build":"rimraf dist && tsc && rollup -c rollup.config.js","prepublishOnly":"npm run build","push":"npm publish --access=public --registry=https://registry.npmjs.org","test":"echo \"Error: no test specified\" && exit 1"},"exports":{"import":"./dist/index.esm.js","require":"./dist/index.cjs.js"},"keywords":["request","axios","fetch","ajax"],"repository":{"type":"git","url":""},"author":"","license":"ISC","devDependencies":{"@babel/core":"^7.17.9","@babel/plugin-transform-runtime":"^7.17.0","@babel/preset-env":"^7.16.11","@rollup/plugin-alias":"^5.1.0","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-commonjs":"^25.0.8","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^15.2.3","@rollup/plugin-typescript":"^12.1.2","@types/node":"^20.10.8","nodemon":"^3.1.9","rimraf":"^3.0.2","rollup":"^2.79.2","rollup-plugin-polyfill-node":"^0.13.0","rollup-plugin-terser":"^7.0.2","tslib":"^2.6.3","typescript":"^5.7.2"},"dependencies":{"axios":"^1.7.9"},"umdModuleName":"NAxios","gitHead":"f64dca31cb4d15f1f5dd10bdb0a777d5d929be3a","_id":"n-axios@0.1.1","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-1JLfS8/4YX9UhG5KhM9v40PukDeLeuxksN47otyeDuaiO1Y1qdfPM8E3+yz6w6PsjAiL1xkFCPOGCi+TVgDqWA==","shasum":"f1eaaff72375c4c711f1d0bdf262a9ee18d1706e","tarball":"https://registry.npmjs.org/n-axios/-/n-axios-0.1.1.tgz","fileCount":11,"unpackedSize":30512,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHSTlDCcAOkLibzJsXwYXs7i4VpR/78gVSgD7zaSHBdZAiAKiL1DIKEVSBPfWuSgHQihr4qaCcuNVUHFrH/3DgjqpA=="}]},"_npmUser":{"name":"dongdong.niu","email":"17621612284@163.com"},"directories":{},"maintainers":[{"name":"dongdong.niu","email":"17621612284@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/n-axios_0.1.1_1739181026814_0.8373123839727121"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-10T09:44:36.284Z","modified":"2025-02-10T09:50:27.225Z","0.1.0":"2025-02-10T09:44:36.564Z","0.1.1":"2025-02-10T09:50:27.029Z"},"license":"ISC","keywords":["request","axios","fetch","ajax"],"repository":{"type":"git","url":""},"description":"基于JS实现的前后端（browser and node）共用请求模块","maintainers":[{"name":"dongdong.niu","email":"17621612284@163.com"}],"readme":"# js-request\n\n#### Introduction\n\nThe browser and node based on the JS implementation share the request module\nCode redundancy, so isolated from https://gitee.com/DieHunter/utils-lib-js\n\n#### Blog introduction\n\nhttps://hunter1024.blog.csdn.net/article/details/126719561\n\n#### Usage instructions\n\n1. Use pnpm i utils-lib-js to install toolkit dependencies (choose one of two)\n2. Install request dependencies using pnpm i js-request-lib (one of two options)\n3. Use pnpm debug for source code debugging\n4. Introduce the js-request-lib module into the code to create a request instance\n\n```javascript\nimport { Request } from \".. /dist/esm/index.js\";\nconst request = new Request(\"https://www.xxx.com\");\n```\n\n5. Make a simple request using the GET method:\n\n```javascript\nrequest\n.GET(\"/users\", { page: 1, limit: 10 })\n.then((response) => {\nconsole.log(\"GET request successful \", response);\n})\n.catch((error) => {\nconsole.error(\"GET request failed \", error);\n});\n```\n\n6. Initiate a POST request\n\n```javascript\nconst requestBody = { username: \"hunter\", password: \"secret\" };\n\nrequest\n.POST(\"/login\", null, requestBody)\n.then((response) => {\nconsole.log(\"POST request successful \", response);\n})\n.catch((error) => {\nconsole.error(\"POST request failed \", error);\n});\n```\n\n7. In addition to GET and POST, the utility class also supports other request methods such as PUT, DELETE, OPTIONS, HEAD, and PATCH. It is used in a similar way, just call the corresponding method:\n\n```javascript\n// Initiate a PUT request\nrequest\n.PUT(\"/users/1\", null, { name: \"hunter\" })\n.then((response) => {\nconsole.log(\"PUT request successful \", response);\n})\n.catch((error) => {\nconsole.error(\"PUT request failed \", error);\n});\n```\n\n8. Interceptors, through which you can add additional headers to the request and process the response data\n\n```javascript\n// Add a request interceptor\nrequest.use(\"request\", (config) => {\n// Execute logic before the request is sent\nconsole.log(\" Request blocker - before request is sent \", config);\nreturn config;\n});\n\n// Add a response interceptor\nrequest.use(\"response\", (response) => {\n// Execute logic after response processing\nconsole.log(\" response interceptor - response processed \", response);\nreturn response;\n});\n// Add an error blocker\nrequest.use(\"error\", (err) => {\n// Execute logic when an error occurs\nconsole.log(\" Error - after processing \", err);\nreturn err;\n});\n```\n\n9. Set additional configurations when creating a request instance, such as setting timeout times, custom requests, etc. :\n\n```javascript\nconst customRequest = new Request(\"https://api.example.com\", {\ntimeout: 5000, // Set the timeout period to 5 seconds\nheaders: {\nAuthorization: \"Bearer YOUR_ACCESS_TOKEN\", // Sets custom request headers\n\"Content-Type\": \"application/json\",\n},\n});\n\ncustomRequest\n.GET(\"/data\")\n.then((response) => {\nconsole.log(\" Request successful \", response);\n})\n.catch((error) => {\nconsole.error(\" Request failed \", error);\n});\n```\n\n#### Contribute\n\n1. Fork the local warehouse\n2. Star Warehouse\n3. Make suggestions\n4. Create a Pull Request\n\n","readmeFilename":"README.en.md"}