{"id":13602478,"url":"https://github.com/wendux/fly","last_synced_at":"2025-05-14T03:09:55.085Z","repository":{"id":41503067,"uuid":"103761921","full_name":"wendux/fly","owner":"wendux","description":":rocket: Supporting request forwarding and Promise based HTTP client for all JavaScript runtimes.","archived":false,"fork":false,"pushed_at":"2022-07-26T04:59:50.000Z","size":746,"stargazers_count":3909,"open_issues_count":90,"forks_count":636,"subscribers_count":73,"default_branch":"master","last_synced_at":"2025-05-11T05:48:31.790Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://wendux.github.io/dist/#/language","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wendux.png","metadata":{"files":{"readme":"README-EN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-16T15:18:24.000Z","updated_at":"2025-05-05T11:36:38.000Z","dependencies_parsed_at":"2022-08-10T02:35:11.264Z","dependency_job_id":null,"html_url":"https://github.com/wendux/fly","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Ffly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Ffly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Ffly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Ffly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wendux","download_url":"https://codeload.github.com/wendux/fly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059510,"owners_count":22007769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T18:01:24.693Z","updated_at":"2025-05-14T03:09:50.043Z","avatar_url":"https://github.com/wendux.png","language":"JavaScript","readme":"[![fly.js](https://github.com/wendux/fly/raw/master/fly.png)](https://wendux.github.io/dist/#/doc/flyio/readme)\n\n[![npm version](https://img.shields.io/npm/v/flyio.svg)](https://www.npmjs.org/package/flyio)\n[![build status](https://travis-ci.org/wendux/fly.svg?branch=master)](https://travis-ci.org/wendux/fly)\n[![coverage](https://img.shields.io/codecov/c/github/wendux/fly/master.svg)](https://codecov.io/github/wendux/fly?branch=master)\n[![size](https://img.shields.io/github/size/wendux/fly/dist/fly.min.js.svg)](https://unpkg.com/flyio@0.3.1/dist/fly.min.js)\n![platform](https://img.shields.io/badge/platforms-All%20JavaScript%20Runtimes-blue.svg)\n\n## Fly.js\n\nSupporting request forwarding and Promise based HTTP client for all JavaScript runtimes.\n\nChinese documentation : [中文文档](https://github.com/wendux/fly/blob/master/README.md)\n\n\n\n### Browser Support\n\n| ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |\n| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |\n| ✔                                        | ✔                                        | ✔                                        | ✔                                        | ✔                                        | \u003e 8                                      |\n\n### Other Platforms  Support\n\u003ctable\u003e\n    \u003ctbody\u003e\n    \u003ctr\u003e\n        \u003ctd align=\"center\" valign=\"middle\"\u003e\n            \u003ca href=\"https://nodejs.org/\"\u003e\n                \u003cimg  src=\"https://github.com/wendux/fly/raw/master/imgs/node.png\" alt=\"node logo\"\u003e\n            \u003c/a\u003e\n        \u003c/td\u003e\n        \u003ctd align=\"center\" valign=\"middle\"\u003e\n            \u003ca href=\"https://mp.weixin.qq.com/\"\u003e\n                \u003cimg  src=\"https://github.com/wendux/fly/raw/master/imgs/mp.png\" alt=\"Mini Program logo\"\u003e\n            \u003c/a\u003e\n        \u003c/td\u003e\n        \u003ctd align=\"center\" valign=\"middle\"\u003e\n            \u003ca href=\"http://facebook.github.io/react-native/\"\u003e\n                \u003cimg  src=\"https://github.com/wendux/fly/raw/master/imgs/rn.png\" alt=\"mpvue logo\"\u003e\n            \u003c/a\u003e\n        \u003c/td\u003e\n        \u003ctd align=\"center\" valign=\"middle\"\u003e\n            \u003ca href=\"http://weex.apache.org/\"\u003e\n                \u003cimg  src=\"https://github.com/wendux/fly/raw/master/imgs/weex.png\" alt=\"weex logo\"\u003e\n            \u003c/a\u003e\n        \u003c/td\u003e\n        \u003ctd align=\"center\" valign=\"middle\"\u003e\n            \u003ca href=\"https://www.quickapp.cn/\"\u003e\n                \u003cimg  src=\"https://github.com/wendux/fly/raw/master/imgs/hp.png\" alt=\"quick app logo\"\u003e\n            \u003c/a\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e  \n\nCurrently the platforms that fly.js supported include  [Node.js](https://nodejs.org/) 、[WeChat Mini Program](https://mp.weixin.qq.com/cgi-bin/wx) 、[Weex](http://weex.apache.org/) 、[React Native](http://facebook.github.io/react-native/) 、[Quick App](https://www.quickapp.cn/) and the browers, all  JavaScript runtimes of these are different. More platforms  are supporting...\n\n## Features\n\n1. Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API\n2. Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser，**light-weight and very light-weight**\n3. Supports  various  JavaScript runtimes\n4. Supports  request and response interceptors。\n5. Automatic transforms for JSON data。\n6. Supports switching the underlying Http Engine, easy to adapt to various JavaScript Runtime.\n7. Supports global Ajax interception on browser\n8. Supports request forwarding in hybrid applications\n\n\n\n\n## Positioning \u0026 target\n\nFly.is  locates to be the ultimate solution for Javascript http requests. That is to say, in any environment that can execute Javascript, as long as it has the ability to access the network, Fly can run on it and provide unified APIs. At the same time, keep lightweight on the browser side.\n\n\n\n## Documentation\n\nYou can find the Fly documentation [on the offical website](https://wendux.github.io/dist/#/language).\n\n[中文文档](https://wendux.github.io/dist/#/doc/flyio/readme)\n\n## Installing\n\nUsing npm \n\n```shell\nnpm install flyio\n```\n\nUsing CDN （on browsers）\n\n```javascript\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/flyio/dist/fly.min.js\"\u003e\u003c/script\u003e\n```\n\nUMD （on browsers）\n\n```http\nhttps://cdn.jsdelivr.net/npm/flyio/dist/umd/fly.umd.min.js\n```\n\n\n\n## Require flyio\n\nThe entry files of  different JavaScript Runtimes may be different, you can refer on the below，\nbut the entries of  Browsers, Node, and React Native are the same。each requirement  ways  of these platforms are as follows:\n\n1. Requiring On browsers、Node、React Native\n\n   ```javascript\n   //for Browsers, Node, and React Native\n   var fly=require(\"flyio\")\n   ```\n\n   The above method requires the default instance of Fly, and you can also create an Fly instance by yourself:\n\n   ```javascript\n   // for browsers and React Native\n   var Fly=require(\"flyio/dist/npm/fly\")\n   // for Node\n   //var Fly=require(\"flyio/src/node\")\n   var fly=new Fly;\n   ```\n\n2. Requiring on WeChat Mini Program\n\n   ```javascript\n   var Fly=require(\"flyio/dist/npm/wx\") \n   var fly=new Fly\n   ```\n\n   If your  project does not use NPM to manage dependencies, you can download the source code directly to your project 。The download links are [wx.js](https://github.com/wendux/fly/tree/master/dist/npm/wx.js) or  [wx.umd.min.js](https://github.com/wendux/fly/tree/master/dist/umd/wx.umd.min.js)  . Download any one, save it to your project directory (assuming named \"lib\") , and then requiring:\n\n   ```javascript\n   var Fly=require(\"../lib/wx\") \n   var fly=new Fly; \n   ```\n\n3. Requiring on Quick App\n\n   On [Quick App](https://www.quickapp.cn/), Fly relies on the `fetch` module, which needs to be defined in the manifest.json first:\n\n   ```java\n     \"features\": [\n        ...\n       {\"name\": \"system.fetch\"}\n     ]\n   ```\n\n   And then create Fly instance:\n\n   ```javascript\n    var fetch = require(\"@system.fetch\")\n    var Fly=require(\"flyio/dist/npm/hap\")\n    var fly=new Fly(fetch)\n   ```\n\n4. Requiring on Weex\n\n   ```javascript\n   var Fly=require(\"flyio/dist/npm/weex\")\n   var fly=new Fly\n   ```\n\nAfter the requirement, you can make the global configuration and add the interceptor to `fly` , and peform network request with `fly`.\n\n## Example\n\nThe following example, if not specified, can be executed in all JavaScript Runtimes.\n\n### Performing a `GET` request\n\n```javascript\nvar fly=require(\"flyio\")\n// Make a request for a user with a given ID,  and the parameter is passed directly in URL\nfly.get('/user?id=133')\n  .then(function (response) {\n    console.log(response);\n  })\n  .catch(function (error) {\n    console.log(error);\n  });\n\n// The parameter is passed by a object\nfly.get('/user', {\n      id: 133\n  })\n  .then(function (response) {\n    console.log(response);\n  })\n  .catch(function (error) {\n    console.log(error);\n  });\n```\n\n### Performing a `POST` request\n\n```javascript\nfly.post('/user', {\n    name: 'Doris',\n    age: 24\n    phone:\"18513222525\"\n  })\n  .then(function (response) {\n    console.log(response);\n  })\n  .catch(function (error) {\n    console.log(error);\n  });\n```\n\n### `POST` request with Url params\n\n```javascript\nfly.get(\"../package.json\", \"xxx=5\", {\n        params: {\n            c: 1\n        }\n    }\n)\n```\n\nThe final url is \"package.json?c=1\u0026xxx=5\".\n\n### Performing multiple concurrent requests\n\n```javascript\nfunction getUserRecords() {\n  return fly.get('/user/133/records');\n}\n\nfunction getUserProjects() {\n  return fly.get('/user/133/projects');\n}\n\nfly.all([getUserRecords(), getUserProjects()])\n  .then(fly.spread(function (records, projects) {\n    // Both requests are now complete\n  }))\n  .catch(function(error){\n    console.log(error)\n  })\n```\n\n### Performing the request by `request`\n\n```javascript\nfly.request(\"/test\",{hh:5},{\n    method:\"post\",\n    timeout:5000 // Set timeout to 5 seconds\n })\n.then(d=\u003e{ console.log(\"request result:\",d)})\n.catch((e) =\u003e console.log(\"error\", e))\n```\n\n\n\n### Sending `URLSearchParams`\n\n```javascript\nconst params = new URLSearchParams();\nparams.append('a', 1);\nfly.post(\"\",params)\n.then(d=\u003e{ console.log(\"request result:\",d)})\n```\n\n\u003e Note that `URLSearchParams` is not supported by all browsers (see [caniuse.com](http://www.caniuse.com/#feat=urlsearchparams)), but there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).\n\n### Sending `FormData`\n\n```javascript\n var formData = new FormData();\n var log=console.log\n formData.append('username', 'Chris');\n fly.post(\"../package.json\",formData).then(log).catch(log)\n```\n\n\u003e Note that `FormData` is not supported by all browsers (see [caniuse.com](http://www.caniuse.com/#feat=urlsearchparams)), but there is a [polyfill](https://github.com/form-data/form-data) available (make sure to polyfill the global environment).  And there are some differences on the way to support formData in node environment. Please click [here](#/doc/flyio/node) for more details\n\n### Requesting Stream\n\n```javascript\nfly.get(\"/Fly/v.png\",null,{\n\tresponseType:\"arraybuffer\"\n}).then(d=\u003e{\n  //d.data is a ArrayBuffer instance\n})\n```\n\n\u003e In browser, the value of responseType can be one of \"arraybuffer\" or \"blob\". In node, you can just set it as \"stream\"\n\u003e\n\n## interceptors\n\nYou can intercept requests or responses before they are handled by `then` or `catch`.\n\n```javascript\n\n// Add a request interceptor\nfly.interceptors.request.use((request)=\u003e{\n    // Do something before request is sent\n    request.headers[\"X-Tag\"]=\"flyio\";\n  \tconsole.log(request.body)\n    // Complete the request with custom data\n    // return Promise.resolve(\"fake data\")\n})\n\n// Add a response interceptor\nfly.interceptors.response.use(\n    (response) =\u003e {\n      // Do something with response data .\n      // Just return the data field of response\n      return response.data\n    },\n    (err) =\u003e {\n      // Do something with response error\n      //return Promise.resolve(\"ssss\")\n    }\n)\n```\n\nThe structures of the `request ` object in request interceptor.\n\n```javascript\n{\n  baseURL,  //base url\n  body, // request parameters\n  headers, //custom request headers\n  method, // http request method\n  timeout, // request time\n  url, // request url (or relative path)\n  withCredentials, // determine whether sending thirdparty cookies in cross-domain request\n  ... // custom field defined in options\n}\n```\n\nThe structures of the `response` object in response interceptor.\n\n```javascript\n{\n  data, //response data\n  engine, //http engine,In browser,it's a instance of XMLHttpRequest.\n  headers, //response headers\n  request  //the origin request object\n}\n```\n\n### Remove interceptors \n\nIf you may need to remove an interceptor later,    just set it to null.\n\n```javascript\nfly.interceptors.request.use(null)\nfly.interceptors.response.use(null,null)\n```\n\n### Perform  an async task in  interceptors\n\nNow,  you can perform  async task in interceptors !\n\nLet's see an example:\n\nbecause of security reasons, we need all the requests to set up a csrfToken in the header, if csrfToken does not exist, we need to request a csrfToken first, and then perform the network request, because the request csrfToken progress is asynchronous, so we need to execute  this async request in request interceptor. the code is as follows:\n\n```javascript\nvar csrfToken=\"\";\nvar tokenFly=new Fly();\nvar fly=new Fly();\nfly.interceptors.request.use(function (request) {\n    //if csrfToken does not exist, we need to request a csrfToken first\n    if(!csrfToken) {\n         // locking the current instance, let the incomming request task enter a \n         // queue before they enter the request interceptors.\n         fly.lock();\n         //Using  another fly instance to request csrfToken.\n         //If use the same fly instance, there may lead a infinite loop:\n         //(The request will go to the interceptor first, and then\n         //enter the interceptor again when launching the new request \n         //in the interceptor....)\n         return tokenFly.get(\"/token\").then((d)=\u003e{\n            request.headers[\"csrfToken\"]=csrfToken=d.data.data.token;\n            //only return the origin `request` object can make the http request continue.\n            // otherwise, the return data will be teated as \"response\" data.\n            return request \n          }).finally(()=\u003e{\n           //fly.clear(); //clear the request queue\n           // unlock the current instance, flush the request queue.   \n           fly.unlock()\n         })  \n        \n    }else {\n        request.headers[\"csrfToken\"]= csrfToken;\n        //This line can be omitted. \n        //If the interceptor doesn't return value, `request` will be used by default.\n        return request \n    }\n})\n```\n\n**Note**: \n\n1. The current fly instance will be locked  when call `fly.lock()` . Once  the fly instance is locked,  the incomming request task maked by it will be hang up and enter a queue before they enter the request interceptors, you can call `fly.unlock()` to continue the requests or call `fly.clear()` to cancel the requests in the queue.\n2. **Only when you return the `request` object  passed by interceptor at the final , the origin http request  will be continued**.  \n\nAnd you can also make an async task in the **response** interceptor. More information about interceptors and examples refer to [flyio interceptor](https://wendux.github.io/dist/#/doc/flyio/interceptor).\n\n## Error handling\n\nIf  the request fails, `catch`  will be called;  the error object's fields as follows :\n\n```javascript\n{\n  message:\"Not Find 404\", //error description\n  status:404, // error code\n  request:{...}, //the request info\n  response:{...}, //the error response,\n  engine:{}, // The Http engine, it's a instance of XmlHttpRequest in browser.\n}\n```\n\n| Code  | Description                              |\n| ----- | ---------------------------------------- |\n| 0     | network error                            |\n| 1     | timeout                                  |\n| 2     | The file was downloaded successfully, but the save failed. **This error only occurred in the node environment** |\n| \u003e=200 | http status code                         |\n\n**Example**\n\n```javascript\nfly.get('/user/12345')\n  .catch(function (error) {\n    console.log('Error', error.message);\n    console.log('Error engine:', error.engine)\n    // The request was made but no response was received\n    // `error.request` holds the request info.\n    console.log('Error request info:',error.request);\n    if (error.response) {\n      // The request was made and the server responded with a status code\n      // that falls out of the range of 2xx and 304\n      console.log(error.response.data);\n      console.log(error.response.status);\n      console.log(error.response.statusText);\n      console.log(error.response.headers);\n    }\n  });\n```\n\n## Request configuration options\n\n**Configurable options**：\n\n```javascript\n{\n // `method` is the request method to be used when making the request\n  method: 'get', // default\n  // `headers` are custom headers to be sent\n  headers:{},\n  // `baseURL` will be prepended to `url` unless `url` is absolute.\n  // It can be convenient to set `baseURL` for an instance of fly to pass relative URLs\n  // to methods of that instance.\n  baseURL:\"\",\n  // `timeout` specifies the number of milliseconds before the request times out.\n  // If the request takes longer than `timeout`, the request will be aborted.\n  timeout:0,  //default\n  // `parseJson` indicates whether or not it is  automatically converted response \n  //  data , the Content-Type of which is application/json, to JSON object,     \n  parseJson:true,\n  //Common URL params\n  params:{}     \n  // `withCredentials` indicates whether or not cross-site Access-Control requests\n  // should be made using credentials\n  withCredentials: false, // default\n}\n```\n\nConfiguration supports **instance level configuration** and **single request configuration**\n\n### Instance level\n\nInstance level configuration can be applied to all requests initiated by the current Fly instance:\n\n```javascript\n// Add common headers\nfly.config.headers={xx:5,bb:6,dd:7}\n// Set timeout\nfly.config.timeout=10000;\n// Set base url\nfly.config.baseURL=\"https://wendux.github.io/\"\n// Common URL params\nfly.config.params={\"token\":\"testtoken\"}\n```\n\n### Single request configuration\n\nSingle request configuration is valid only once:\n\n```javascript\nfly.request(\"/test\",{hh:5},{\n    method:\"post\",\n    timeout:5000 //超时设置为5s\n})\n```\n\n\u003e If the single configuration and the instance configuration conflict, the single request configuration is preferred .\n\n## API\n\n#### `fly.get(url, data, options)`\n\n#### `fly.post(url, data, options)`\n\nIn browser environment, the type of data can be:\n\n```shell\nString|Json|Object|Array|Blob|ArrayBuffer|FormData\n```\n\n`options` is the  request configuration。\n\n\n\n#### `fly.request(url, data, options)`\n\nWhen you use this API, you should explicitly specify  the method of options, and the default method is `get`\n\n```javascript\n// Perform a get request\nfly.request(\"/user/8\" null, {method:\"get\"})\n// Perform a delete request\nfly.request(\"/user/8/delete\", null, {method:\"delete\"})\n// Perform a put request\nfly.request(\"/user/register\", {name:\"doris\"}, {method:\"PUT\"})\n......\n```\n\nThis API is suitable for use in RESTful API scenarios. For convenience, the corresponding alias methods are provided\n**alias**\n\n`fly.put(url, data, options)`\n\n`fly.delete(url,data,options)`\n\n`fly.patch(url,data,options)`\n\n### Concurrency\n\nHelper functions for dealing with concurrent requests.\n\n##### `fly.all([])`\n##### `fly.spread(callback)`\n\nThe parameter of all is an array of `promise`,  `then` will be called only when all requests are successful, and` catch` will be called as long as one fails.\n\n## Using application/x-www-form-urlencoded format\n\nBy default, fly serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options.\n\n### By specifying `content-type` request header\n\nWhen you specify  `content-type` value as \"application/x-www-form-urlencoded\", fly will encode the request data automatically, for example：\n\n```javascript\nfly.post(\"../package.json\",{aa:8,bb:9,tt:{xx:5}},{headers:{\n    \"content-type\":\"application/x-www-form-urlencoded\"\n}})\n.then(console.log)\n```\n\nThis method is universal, which means that it can work well in any JavaScript runtime. There are also some other ways for some specific platforms:\n\n### Other ways\n\n#### Browser\n\nIn a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as follows:\n\n```js\nvar params = new URLSearchParams();\nparams.append('param1', 'value1');\nparams.append('param2', 'value2');\nfly.post('/foo', params);\n```\n\n\u003e Note that `URLSearchParams` is not supported by all browsers (see [caniuse.com](http://www.caniuse.com/#feat=urlsearchparams)), but there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).\n\nAlternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:\n\n```js\nvar qs = require('qs');\nfly.post('/foo', qs.stringify({ 'bar': 123 }));\n```\n\n#### Node.js\n\nIn node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:\n\n```js\nvar querystring = require('querystring');\nfly.post('http://something.com/', querystring.stringify({ foo: 'bar' }));\n```\n\nYou can also use the [`qs`](https://github.com/ljharb/qs) library.\n\n\n\n## Promises\n\nFly depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises).\nIf your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).\n\n## TypeScript\nfly includes [TypeScript](http://typescriptlang.org) definitions.\n```typescript\nimport fly from \"flyio\"\nfly.get('/user?ID=12345');\n```\n## Creating  an instance\n\nYou can create a new instance of Fly , and then apply different configurations:\n\n```javascript\n// Notice require path is  \"flyio/dist/npm/fly\"\nvar  Fly=require(\"flyio/dist/npm/fly\")\nvar nFly=new Fly();\n// Apply different configurations\nnFly.config.timeout=15000\nnfly.interceptors.request.use(...)\n```\n\n\n\n## Http Engine\n\nFly introduces the concept of Http Engine, and Http Engine is the engine that really initiates http requests. This is typically XMLHttpRequest in browser environment, and in Node environments, any module or library that can initiate a network request can be implemented. Fly can switch the Http Engine freely. In fact, Fly is implemented by switching Http Engine, supporting both the browser environment and the Node environment.However, Http Engine is not limited to Node and browser environment, also can be Android, IOS, electron and so on, it is because of these, Fly has a very unique and powerful feature \"request forwarding\". Based on the request forwarding, we can implement some useful functions, such as redirecting all the HTTP requests of the hybrid application to Native, and then complete the network request on natvie side.  The benefit of this is that  we can perform unified certificate validation, cookie management, access control and son on on natvie.  More details click here  [http engine](https://wendux.github.io/dist/#/doc/flyio-en/engine) .\n\n## Global Ajax interception\n\nIn browsers, you can intercept global Ajax requests by replacing XMLHttpRequest with Fly engine, regardless of what network library the upper layer uses.  More details click here [Ajax hook](https://wendux.github.io/dist/#/doc/flyio-en/hook)\n\n## Using in Node\n\nWhether in browser environment or in Node environment, Fly provides a unified Promise API in the upper layer. This means that, regardless of whether you are in web development or node development, you can perform HTTP requests in the same way. However, because of the difference of node and browser environment, under the environment of Node, Fly in addition to basic API support, also provides some enhancements to the API, the API mainly involves the file download, file upload,  HTTP agents and other powerful features, please refer to [Node enhanced API](https://wendux.github.io/dist/#/doc/flyio-en/node) .\n\n\n## Size\n\nIn  browser environment, the size of a library is very important. In this regard, Fly is doing a good job, on the on hand  Fly maintains the powerful function, on the other hand, Fly control its body to the minimum. Min is only about 4.6K, and GZIP is less than 2K after compression, and the volume is 1/4 of Axios。\n\n## Project structure\n\nLearn the project structure of Fly.js please refer to : [Fly.js source structure](https://wendux.github.io/dist/#/doc/flyio-en/files) \n\n\n## Finally\n\nWelcome stars 。\n\n\n\n\n","funding_links":[],"categories":["JavaScript","组件和库"],"sub_categories":["审核规范"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwendux%2Ffly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwendux%2Ffly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwendux%2Ffly/lists"}