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

@quickapp-eco/quickapp-axios

v0.1.1

Published

网络请求axios工具库在快应用平台上的实现

Downloads

13

Readme

quickapp-axios

网络请求axios工具库在快应用平台上的实现

特性

  • 从快应用中出创建 XMLHttpRequests
  • 支持 Promise API
  • 创建建fetch请求别名
  • 拦截请求和响应
  • 转换请求和响应数据

平台支持

QuickApp

manifest.json 配置

{ "name": "system.fetch" }

安装

使用 npm:

$ npm install @quickapp-eco/quickapp-axios

示例

执行 GET 请求

// Make a request for a user with a given ID
fetch.get('/example?id=12345')
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.log(error);
    });

// Optionally the request above could also be done as
fetch.get('/example', {
        params: {
            id: 12345
        }
    })
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.log(error);
    });

执行 POST 请求

fetch.post('/example', {
        name: 'HeartCloud',
        password: '12345'
    })
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.log(error);
    });

fetch API

可以通过将相关配置传递给 fetch 来进行请求

fetch(config)
// 发送一个 POST 请求
fetch({
    method: 'post',
    url: '/example/12345',
    data: {
        name: 'HeartCloud',
        password: '12345'
    }
});

请求方法别名

为了方便起见,已经为所有支持的请求方法提供了别名。

fetch. get(url[, config])
fetch. delete(url[, config])
fetch. head(url[, config])
fetch. options(url[, config])
fetch. post(url[, data[, config]])
fetch. put(url[, data[, config]])
fetch. patch(url[, data[, config]])

创建实例

您可以使用自定义配置创建axios的新实例。

fetch. create([config])
let instance = fetch.create({
    baseURL: 'https://www.example.com/api/',
    header: {
        'X-Custom-Header': 'example'
    }
});

请求配置

这些是用于发出请求的可用配置选项。 只有url是必需的。 如果未指定method,请求将默认为GET。

拦截器

你可以截取请求或响应在被 then 或者 catch 处理之前

// 添加请求拦截器
fetch.interceptors.request.use(config => {
    // Do something before request is sent
    return config;
}, function(error) {
    // Do something with request error
    return Promise.reject(error);
});

// 添加响应拦截器
fetch.interceptors.response.use(response => {
    // Do something with response data
    return response;
}, function(error) {
    // Do something with response error
    return Promise.reject(error);
});

如果你之后可能需要删除拦截器。

let myInterceptor = fetch.interceptors.request.use(function() {
    /*...*/ });
fetch.interceptors.request.eject(myInterceptor);

你可以将拦截器添加到fetch的自定义实例。

let instance = fetch.create();
instance.interceptors.request.use(function() {
    /*...*/ });

TypeScript

fetch包括 TypeScript 定义。

import fetch from '@quickapp-eco/quickapp-axios';
fetch.get('/example?id=12345');

License

MIT