Coder Social home page Coder Social logo

wendux / fly Goto Github PK

View Code? Open in Web Editor NEW
3.9K 3.9K 640.0 746 KB

:rocket: Supporting request forwarding and Promise based HTTP client for all JavaScript runtimes.

Home Page: https://wendux.github.io/dist/#/language

License: MIT License

JavaScript 88.92% HTML 10.70% TypeScript 0.37%

fly's Issues

interceptors 拦截出错

interceptors 拦截,如果 response.data 为 ‘’,即空值 , return response.data返回了整个response, 而不是一个空值

npm引入fiyio失败

image
按照提示继续安装完后,依然提示失败
image
node版本 v8.9.3
npm版本 v5.6.0

fly支持序列化器吗?

就像axios这样,在创建实例的时候指定参数的序列化方式。paramsSerializer, transformRequest

const $solr  = axios.create({ 
    baseURL: '/baseurl/solr/', 
    data: { indent: "off", wt: 'json', q: '*:*' },
    paramsSerializer: (params) => Qs.stringify(params, { arrayFormat: 'repeat', encode: true }),
    transformRequest: (data)   => Qs.stringify(data,   { arrayFormat: 'repeat', encode: true }),
})

请问如何设置 Content-Type

没有找到相关文档
如下参考 fetch 的配置方法似乎也没用 ?

headers: { 'Content-Type': 'application/json; charset=utf-8'}

关于 400/500 错误的处理机制

400 错误是客户端错误,应该抛出错误,但是 response 还是应该反序列化为 json (如果 content-type 是 json 的话) 还是有必要的,因为需要传递错误信息,甚至连 500 错误都应该尝试这样做

对restFul支持问题

由于小程序的wx.request使用不了patch方法,简单封装wx.request的话,并不能使用patch方法,看到Fly文档说有说到可以用使用patch方法。怎么才能让它支持使用patch方法呢?是需求我自己更换别的http引擎吗?求解。

反馈两个问题

使用场景:小程序

一、请求拦截器在多个并发请求时无效;
二、多个并发请进时,回调好像不能同时获取到;

微信小程序环境无法修改Content-Type

 this.$http
      .get(
        "https://api.douban.com/v2/movie/in_theaters?apikey=0b2bdeda43b5688921839c8ecb20399b&city=%E5%8C%97%E4%BA%AC&start=0&count=100&client=&udid=",
        {
          headers: {
            "Content-Type": "json",
            token: "123"
          }
        }
      )
      .then(d => {
        //输出请求数据
        console.log(d.data);
        //输出响应头
        console.log(d.header);
      })
      .catch(err => {
        console.log(err.status, err.message);
      });

tim 20180329112219

希望能添加选项关闭自动 JSON 解析

某个接口的返回值为以下格式,且返回的 Content-Type 为 application/json

var tag_jsonp =[{
"newsid":"351341",
"img":"http://img.ithome.com/newsuploadfiles/thumbnail/2018/3/351341_240.jpg",
"newstitle":"乐视网复牌跌停,封单逾70万手",
"postdate":"2018.03.16",
"url":"https://www.ithome.com/html/it/351341.htm"
}]

目前的判断方式依然会自动进行 JSON 解析,导致出错

if ((engine.getResponseHeader("Content-Type") || "").indexOf("json") !== -1
  && !utils.isObject(response)) {
  response = JSON.parse(response);
}

后端是第三方的,所以无法控制

依赖找不到fs net tls dgram dns

直接使用其他人项目run dev没事。但我自己的项目重装了flyio多次之后还是跑不动啊。。require('flyio')就报错
flyio

weex中get无反应

let stream = weex.requireModule('stream');
var modal = weex.requireModule('modal')
var Fly = require("flyio/dist/npm/weex")

var fly=new Fly

export default {
methods:{

/*是否iphoneX*/
isIpx() {
  return weex && (weex.config.env.deviceModel === 'iPhone10,3' || weex.config.env.deviceModel === 'iPhone10,6');
},

flyGET(api, callback){
  modal.toast({message: '加载fly'})
  return fly.get(api).then(callback)
},

get 没有反应, 怎么回事,

关于报错信息

我在使用拦截器的时候,发现报错信息只有一个status 是可用的 我在测试中遇到过 只返回过status 0 的问题,想询问下 ,这一块的处理如何自定义呢?我想能够得到服务器返回的整个body的内容?

如何以发送application/x-www-form-urlencoded编码数据

首先遇到的问题是,我在对一条接口进行post请求的时候,并且需要传递参数对象,代码如下:
api
然后发现网络数据异常,于是用wx原生进行了post请求发现并无问题对比Request Headers发现了异同:

aaa

请求添加对 PUT 和 DELETE 等 HTTP 方法的支持

鉴于 Restful API 的广泛使用,仅仅 GET 和 POST 似乎还不太够,Fly 用起来很爽,如果能加上对 PUT 和 DELETE 等 HTTP 方法的支持就更好了。

PS:本以为可以通过request()方法手动发起,结果看到非 GET 请求只有 engine.open('POST'),只好来提 Issue 了

有类似onUploadProgress的实现么

我打算用fly做一个上传文件的功能,需要显示上传进度,axios可以通过配置onUploadProgress获得上传进度,不知道fly有没有相应的实现?

补充一下,我说的是浏览器环境

跨域请求响应头数据缺失

这是使用ajax和postman能获取到的数据:

Response Headers:
x-powered-by:"Iris Web Framework"
vary:"Origin"
x-access-token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mbyI6eyJpZCI6MjEsInVzZXJuYW1lIjoi5p2O5r2H5r2HIiwicGhvbmUiOjE3NjEyODg3ODY4fSwiaWF0IjoxNTI0NTQyNjY4LCJleHAiOjE1MjQ1NDk4Njh9.Q1koqxGS9Aa6auS8dzuXTf21LvA4kaFd1woSlEjQpxI"
content-type:"application/json; charset=utf-8"
x-response-time:"19ms"
content-length:"1153"
date:"Tue, 24 Apr 2018 04:04:28 GMT"
connection:"keep-alive"

这是flyio获得的headers:

headers:
content-type :"application/json; charset=utf-8"

我们需要在header添加自定义参数和获取服务器返回的自定义响应头参数,但是各种尝试都无法获取到具体参数,通过拦截也无法实现,希望官方能够提供解决办法,谢谢了。

mpvue中使用fly,如何传额外参数进拦截器?

在request拦截器中,可以弹出loading提高用户体验,这很棒。
但我在实际项目中,有的请求需要弹出loading,有的请求不需要,可以在发起请求的时候传一些参数进拦截器,拦截器再根据这个参数判断是否要显示loding这样吗?比如说:

fly.get(url,params,{isShowLoading:false});

不知有没有类似的解决方法?

0.4.7的问题

升级到0.4.7后 post请求里传入的data变成了 [object object],0.4.6没问题

快应用中,fly在没断网时正常,断网后出错

麻烦看下,崩溃日志:
JsConsole: undefined:914: TypeError: Cannot read property 'split' of null
TypeError: Cannot read property 'split' of null
at AjaxEngine.engine.onload (eval at sr (unknown source), :914:76)
at AjaxEngine._call (eval at sr (unknown source), :533:55)
at eval (eval at sr (unknown source), :650:47)
at Object.request.complete (eval at sr (unknown source), :992:26)
at K.e.callbacks.(anonymous function) (:1:11354)
at Z (:1:10006)
at Object.hr [as processInvokeCallback] (:2:18226)
at Object.createPage.t.processInvokeCallback.tu.(anonymous function) [as execInvokeCallback] (:2:23495)
at global.(anonymous function) (:4:30804)
at :1:1

在response拦截器里reject的话,有时候能catch 到error,有时候不行

拦截器配置如下:

    fly.interceptors.response.use(
    (response) => {
      //只将请求结果的data字段返回
      console.log('fly.interceptors response=' + JSON.stringify(response.data));
      // return response.data
      return Promise.reject(new Error("heheheeh", 99))
    },
    (err) => {
      console.log('fly.interceptors: error message=' + JSON.stringify(err));
    }
  )

调用如下:

  this.$app.$def.fly.get('https://www.sojson.com/open/api/weather/json.shtml?', {
      city: '上海'
    })
    .then(function (response) {
      console.log('success result=' + JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
      console.log('error msg=' + error.message);
      console.log('error status=' + error.status);
    });

有时候能进入catch,有时候不行,打断的也是

微信小程序中FormData问题

fly.interceptors.request.use((config, promise) => { if (config.method === 'POST') { let data = new FormData() for (let key in config.body) { data.append(key, config.body[key]) } config.body = data } console.log(config) return config })
我在拦截器里面处理POST数据 但是不能正常工作 request header content-type 还是 json 是哪里有问题吗?

使用qs变换表单数据,小程序中仍然发送的是未经变换的请求

拦截器

fly.interceptors.request.use((config,promise)=>{
    const symbol = config.url.indexOf('?') === -1 ? '?' : '&';
    config.url += `${symbol}from=app&appVersion=2.1.1024`;// TODO: 接口需不要需要针对小程序做修改
    config.headers["token"] = auth.getToken();
    // 修改request
    if (config.method === "POST") {
        config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        config.body = qs.stringify(config.body);
    }
    return config;
});

qs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.