{"id":30300299,"url":"https://github.com/bfncs/request-fluture","last_synced_at":"2025-08-17T04:32:53.276Z","repository":{"id":65488814,"uuid":"102508841","full_name":"bfncs/request-fluture","owner":"bfncs","description":":butterfly: Simple HTTP requests with Fluture and request.","archived":false,"fork":false,"pushed_at":"2019-03-05T21:34:28.000Z","size":221,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-22T13:13:59.742Z","etag":null,"topics":["fantasy-land","fluture","functional","http","https","monad","promise","request","xhr"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/request-fluture","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/bfncs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-05T17:09:03.000Z","updated_at":"2021-03-02T09:05:16.000Z","dependencies_parsed_at":"2023-01-25T16:45:17.424Z","dependency_job_id":null,"html_url":"https://github.com/bfncs/request-fluture","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/bfncs/request-fluture","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfncs%2Frequest-fluture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfncs%2Frequest-fluture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfncs%2Frequest-fluture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfncs%2Frequest-fluture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfncs","download_url":"https://codeload.github.com/bfncs/request-fluture/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfncs%2Frequest-fluture/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270807430,"owners_count":24649342,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["fantasy-land","fluture","functional","http","https","monad","promise","request","xhr"],"created_at":"2025-08-17T04:32:23.772Z","updated_at":"2025-08-17T04:32:53.243Z","avatar_url":"https://github.com/bfncs.png","language":"JavaScript","readme":"# request-fluture\n[![Build Status](https://travis-ci.org/bfncs/request-fluture.svg?branch=master)](https://travis-ci.org/bfncs/request-fluture)\n\nSimple HTTP requests with [Flutures](https://github.com/fluture-js/Fluture) and [request](https://github.com/request/request).\n\nThis is a wrapper around `request` to offer a Fluture API (instead of callback- or promise-based).\n\n\n## Install\n\n```bash\n# If you are using npm\nnpm install request-fluture request fluture\n\n# If you are using yarn\nyarn add request-fluture request fluture\n```\n\n\n## Usage\n\nCall the exported function with either a `url` or an `options` object [according to the `request` docs](https://github.com/request/request#requestoptions-callback).\nIt returns a `Fluture` for your pending request. You can use the whole [`Fluture API`](https://github.com/fluture-js/Fluture#documentation) to do stuff with your result.\n\n```js\nconst request = require('request-fluture');\n\nrequest('http://example.com')\n    .fork(\n       error =\u003e console.error('Oh no!', error),\n       response =\u003e console.log('Got a response!', response)\n     );\n```\n\nFetch data from a REST API and extract some specific data.\n```js\nconst request = require('request-fluture');\nconst { encase } = require('fluture');\n\nrequest({url: 'https://api.github.com/users/github', headers: {'User-Agent': 'request-fluture'}})\n    .map(res =\u003e res.body)\n    .chain(encase(JSON.parse))\n    .map(user =\u003e user.name)\n    .fork(\n      console.error,\n      name =\u003e console.log(`The requested username is ${name}.`)\n    );\n```\n\nYou can cleanly [`cancel`](https://github.com/fluture-js/Fluture#cancellation) the request fluture anytime after using a [consuming function](https://github.com/fluture-js/Fluture#consuming-futures) like `fork` on it:\n```js\nconst request = require('request-fluture');\n\nconst cancel = request('http://example.com')\n    .fork(console.error, console.log);\n\n// Cancel the request\nsetTimeout(cancel, 1000);\n```\nThis is for example also used to cleanly cancel requests whose results are not interesting anymore like when using [`race`](#race), saving your precious bandwidth.\n\n## Examples\n\n### Race\n\n[Race](https://github.com/fluture-js/Fluture#race) multiple requests against each other and resolve to the first settled request.\n\n```js\nconst Future = require('fluture');\nconst request = require('request-fluture');\n\n// Race two requests against each other…\nrequest('http://example.com/foo')\n  .race(request('http://example.com/bar'))\n  .fork(console.error, console.log);\n\n// …or race an array of requests\nconst first = futures =\u003e futures.reduce(Future.race, Future.never);\nfirst([\n  request('http://example.com/foo'),\n  request('http://example.com/bar'),\n  request('http://example.com/baz')\n])\n  .fork(console.error, console.log);\n```\n\nYou can easily implement a timeout for your requests with this:\n\n```js\nconst Future = require('fluture');\nconst request = require('request-fluture');\n\nrequest('http://example.com/foo')\n  .race(Future.rejectAfter(1000, 'Timeout'))\n  .fork(console.error, console.log);\n```\n\n\n### Parallel requests\n\nExecute five requests with maximum `5` requests in parallel.\n\n```js\nconst Future = require('fluture');\nconst request = require('request-fluture');\n\nconst tenRequests = Array.from(Array(10).keys())\n  .map(resource =\u003e request(`http://example.com/${resource}`));\n\nFuture.parallel(5, tenRequests)\n  .fork(\n    console.error,\n    results =\u003e { results.forEach(console.log); }\n  );\n```\n\n\n## Prior art\n\nThis is just a slight extension of a [Gist](https://gist.github.com/Avaq/e7083ffc7972bb1d4c88239b51eb4a79) by @Avaq.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfncs%2Frequest-fluture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfncs%2Frequest-fluture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfncs%2Frequest-fluture/lists"}