npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

axios-ajax

v0.0.24

Published

axios-ajax

Downloads

52

Readme

axios-ajax

功能介绍

  1. 针对axios使用二次封装,更友好的发请求
  2. 对外输出 axiosInstance 与 restful 对象, axios 为新实例对象

安装

npm install axios-ajax

使用

// 内部默认axios参数
// const defaultOptions = {
//     method: 'get', // method:  get post delete put patch
//     withCredentials: true, // 设置该属性可以把 cookie 信息传到后台 
//     headers: {
//         // headers 的键是不区分大小写的
//         Accept: 'application/json',
//         //'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
//         'Content-Type': 'application/json; charset=utf-8'
//     },
//     data: null
// }

import {axiosInstance,restful,setInstanceDefaultOptions} from 'axios-ajax' 
// 可以使用setInstanceDefaultOptions(axiosRequestConfig)函数追加的默认参数

// 第一个参数为url,第二个参数为数据,第三个参数为原生 axios requestConfig
// 默认baseURL为" 'api/' ,可以通过第三个参数进行修改
//restful[method](url,data,axiosRequestConfig) 
const response = await restful.get('getUser',{a:1,b:2}) // 发送GET api/getUser?a=1&b=2 请求
const response = await restful.post('http://www.com/getUser',{a:1,b:2}) // 发送POST http://www.com/getUser 请求
const response = await restful.put('http://www.com/api',{a:1,b:2})
const response = await restful.delete('http://www.com/api',{a:1,b:2})
const response = await restful.patch('http://www.com/api',{a:1,b:2})

// axiosInstance 为axios实例对象,
// 你可以继续使用请求与响应拦截器:
// axiosInstance.interceptors.request.use(requestConfig => {},error => {})
// axiosInstance.interceptors.response.use(response => {},error=>{})

restful 动词介绍

// GET(SELECT):从服务器取出资源(一项或多项)。
// POST(CREATE):在服务器新建一个资源。
// PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源)。
// PATCH(UPDATE):在服务器更新资源(客户端提供改变的属性)。
// DELETE(DELETE):从服务器删除资源。

相关 restful api 介绍链接:http://www.ruanyifeng.com/blog/2014/05/restful_api.html