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

@juxi/app-network

v1.0.2

Published

桔夕app 网络通用配置

Downloads

2

Readme

App 网络通用配置

基于 App采用 React Native 和 小程序采用Taro技术栈进行开发。两者的技术栈都是基于React。 所以抽离部分网络api到公共组件中。实现两端业务同步。

项目文件介绍

  • http-config: 项目配置
  • http-encoding: 编码方式(URLEncoding, JSONEncoding)
  • http-method: 常用的方法,采用全大写
  • http-header: 常用的便捷header
  • request文件: 存放各个业务场景的请求参数,根据业务不断添加

设计思路

header、method、config 封装常用的方法、常量。

http-encoding

主要针对 params。

  • URLEncoding: 把 params 转成 xx=xx&xx=xx的形式拼接在url的query部分(方便的可以直接在url后面自己拼接,不通过params的方式)
  • JSONEncoding: 把 params 转成data 放在 body 部分

request文件

单个request文件存放某类业务相似的请求。最好和后端文档同步。用户类请求相关的api放到同个文件下, 命名为 http-request-xxx.js。 不同业务的api,单独新开一个文件。

举个🌰


export const HTTPRequestGoods = {
    // 对应单个api
    get: (keyword) => {
        return {
            url: HTTPBaseURL + '?seach=' + keyword,
            params: null,
            method: HTTPMethod.GET,
            encoding: HTTPEncoding.JSONEncoding,
            header: null
        }
    },
    add: (name) => {
        url: HTTPBaseURL + '/add'
    }
    .
    .
    .
    .

}

按照以下格式去实现

{
    url: 必要
    params: 可选
    method: 可选
    encoding: 可选
    header: 可选
}

命名关键字: get、update、delete、add

具体使用

App端 为例,首先需要对网络api进行进一步封装

RN 项目封装(仅供参考):

// HTTP.js 文件
export function request(config, success, failure, completion) {
    let url = config.url
    let encoding = config.encoding || HTTPEncoding.URLEncoding
    let method = config.HTTPMethod || HTTPMethod.GET
    let header = config.header || DefaultHeader
    return axios.request({
        url: config.url,
        method: method,
        params: props.params,
        header: header
    })
}

上传调用

// 使用的时候
let config = HTTPRequestUser.login(phone, password)
HTTP.request(config, (response) => {

},(error) => {

  })