{"id":20569606,"url":"https://github.com/xiaody/fetchy-request","last_synced_at":"2026-04-25T03:23:22.457Z","repository":{"id":35141908,"uuid":"39360333","full_name":"xiaody/fetchy-request","owner":"xiaody","description":"Request done right","archived":false,"fork":false,"pushed_at":"2020-04-30T18:26:57.000Z","size":14,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T14:42:03.928Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xiaody.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-20T03:04:50.000Z","updated_at":"2019-08-08T17:04:33.000Z","dependencies_parsed_at":"2022-08-18T00:01:03.935Z","dependency_job_id":null,"html_url":"https://github.com/xiaody/fetchy-request","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xiaody/fetchy-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaody%2Ffetchy-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaody%2Ffetchy-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaody%2Ffetchy-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaody%2Ffetchy-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiaody","download_url":"https://codeload.github.com/xiaody/fetchy-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaody%2Ffetchy-request/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32248648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T03:17:44.950Z","status":"ssl_error","status_checked_at":"2026-04-25T03:16:45.208Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-11-16T05:08:57.449Z","updated_at":"2026-04-25T03:23:17.449Z","avatar_url":"https://github.com/xiaody.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/fetchy-request.svg)](http://badge.fury.io/js/fetchy-request)\n[![Build Status](https://travis-ci.org/xiaody/fetchy-request.svg)](https://travis-ci.org/xiaody/fetchy-request)\n[![Dependency Status](https://david-dm.org/xiaody/fetchy-request.svg)](https://david-dm.org/xiaody/fetchy-request)\n\nA simple way to make simple http requests.\n\n## Install\n\n```bash\nnpm install --save fetchy-request\n## Notice: if you are using a legacy node version\n## which does not contain a native Promise,\n## please install and use a polyfill by yourself.\n# npm install --save bluebird\n```\n\n## Usage\n**In general, the API is pretty much a mixture of the [fetch API] and the popular [request] package.**\n\nA simple GET:\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest('http://open.meituan.com/cool-api/?k1=v1\u0026k2=v2')\n    .then(function (response) {\n        return response.json()\n    }).then(function (json) {\n        console.log('parsed json', json)\n    })\n```\n\nThe same GET \u003csup\u003e[1]\u003c/sup\u003e:\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest({\n    uri: 'http://open.meituan.com/cool-api/'\n    method: 'GET',\n    qs: {\n        k1: 'v1',\n        k2: 'v2'\n    }\n})\n```\n\nA simple POST:\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest({\n    uri: 'http://open.meituan.com/cool-api/'\n    method: 'POST',\n    form: {\n        username: 'admin',\n        password: 'hackmeifyoucan!'\n    }\n})\n```\n\nAnother POST:\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest({\n    uri: 'http://open.meituan.com/cool-api/'\n    method: 'POST',\n    headers: {\n        'Content-Type': 'application/json'\n    },\n    body: '{\"json is\": \"Great!\"}'\n})\n```\n\n`qs` and `form` is stringified by [qs];\nPOST `body` overwrites `form`.\n\nFile uploads are not yet supported.\n\n## Timeout\n\nSet *response* timeout in millisecond.\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest({\n        uri: 'http://open.meituan.com/cool-api/?k1=v1\u0026k2=v2'\n        timeout: 2000\n    })\n```\n\n## Retry\n\nRetry for any http 5xx server errors or local syscall errors:\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest({\n        uri: 'http://open.meituan.com/cool-api/?k1=v1\u0026k2=v2'\n        retry: 2\n    })\n```\n\n## Proxy\nAutomatically use `process.env.HTTP_PROXY` for http requests.\n\n```bash\nHTTP_PROXY='http://127.0.0.1:8888' node server.js\n```\n\n**Notice: this is purposely designed for debugging. DO NOT use in production environments.**\n\n## Events/Timing/Error Reporting\n\n```javascript\nlet request = require('fetchy-request')\nrequest({\n    uri: 'http://open.meituan.com/poi/12345?k1=v1\u0026k2=v2',\n    // .displayName will be used in errors' message,\n    // default to the `.uri` if omitted\n    displayName: 'open.meituan.com/poi',\n    // label is readable in any events callback\n    label: ['tag1', 'tag2']\n})\n\nrequest.on('beforeSend', function (requestOptions) {\n})\n\nrequest.on('success', function (incommingMsg, requestOptions) {\n    console.log(requestOptions.displayName, 'timing:', incommingMsg.timing.response - incommingMsg.timing.start)\n    // =\u003e open.meituan.com/poi timing: 200\n    console.log(requestOptions.label)\n    // =\u003e ['tag1', 'tag2']\n})\n\nrequest.on('failure', function (error, requestOptions) {\n    console.warn(error.message)\n    // =\u003e 502 Bad Gateway: open.meituan.com/poi\n    console.log(requestOptions.displayName, 'request failed after', err.timing.error - err.timing.start, 'ms')\n    // =\u003e open.meituan.com/poi request failed after 300 ms\n    console.log(requestOptions.label)\n    // =\u003e ['tag1', 'tag2']\n})\n```\n\n## Error Handling Sugar\n\n```javascript\nlet request = require('fetchy-request')\n\nrequest('http://unstable.meituan.com/user.xml?user=xiaody')\n    .then(function (response) {\n        const fallback = { user: '', phone: '', error: true }\n\n        // request failed\n        if (!response.ok)\n            return fallback\n\n        // in case its not JSON\n        return response.safeJson(function (e) {\n            send_error_msg('error occurs when parse response as JSON:', e)\n            return fallback\n            // the error `e` will be returned if this error handler is omitted;\n            // you can also pass in the fallback as a second argument, which overwrite the return value of the error handler.\n        })\n    }).then(function (userInfoOrFallback) {\n        // use userInfo or fallback\n    })\n```\n\n_\n[1] In fact, there is a little difference when they come to error reporting.\n_\n\n\n[fetch api]: https://fetch.spec.whatwg.org/#fetch-api\n[request]: https://www.npmjs.com/package/request\n[qs]: https://www.npmjs.com/package/qs\n[querystring]: https://iojs.org/api/querystring.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaody%2Ffetchy-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiaody%2Ffetchy-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaody%2Ffetchy-request/lists"}