{"id":18541309,"url":"https://github.com/cyclejs/cycle-fetch-driver","last_synced_at":"2025-04-09T18:31:05.497Z","repository":{"id":57105157,"uuid":"42910139","full_name":"cyclejs/cycle-fetch-driver","owner":"cyclejs","description":"Cycle.js for the Fetch API","archived":false,"fork":false,"pushed_at":"2016-02-03T08:50:16.000Z","size":20,"stargazers_count":27,"open_issues_count":7,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T00:55:12.857Z","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/cyclejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-09-22T03:54:07.000Z","updated_at":"2019-08-18T16:52:07.000Z","dependencies_parsed_at":"2022-08-21T03:00:30.328Z","dependency_job_id":null,"html_url":"https://github.com/cyclejs/cycle-fetch-driver","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyclejs%2Fcycle-fetch-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyclejs%2Fcycle-fetch-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyclejs%2Fcycle-fetch-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyclejs%2Fcycle-fetch-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyclejs","download_url":"https://codeload.github.com/cyclejs/cycle-fetch-driver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248087682,"owners_count":21045564,"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-11-06T20:04:41.765Z","updated_at":"2025-04-09T18:31:05.167Z","avatar_url":"https://github.com/cyclejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cycle Fetch Driver\n\nA [Cycle.js](http://cycle.js.org) [Driver](http://cycle.js.org/drivers.html) for making HTTP requests, using the [Fetch API](https://fetch.spec.whatwg.org/).\n\n## Install\n\n```sh\nnpm install @cycle/fetch\n```\n\n## API\n\n### ```makeFetchDriver(scheduler: Scheduler) -\u003e fetchDriver: function```\n\nFactory that returns a fetch driver. It takes an optional ```scheduler``` argument to pass into ```fromPromise```.\n\n## Usage\n\nBasics:\n\n```js\nimport 'whatwg-fetch' // polyfill if you want to support older browsers\nimport Cycle from '@cycle/core';\nimport { makeFetchDriver } from '@cycle/fetch';\n\nfunction main(responses) {\n  // ...\n}\n\nconst drivers = {\n  HTTP: makeFetchDriver()\n}\n\nCycle.run(main, drivers);\n```\n\nSimple and normal use case:\n\n```js\nfunction main({ DOM, HTTP }) {\n  const HELLO_URL = 'http://localhost:8080/hello';\n  const request$ = Rx.Observable.just(HELLO_URL);\n  const vtree$ = HTTP\n    .byUrl(HELLO_URL)\n    .mergeAll()\n    .flatMap(res =\u003e res.text()) // We expect this to be \"Hello World\"\n    .startWith('Loading...')\n    .map(text =\u003e\n      h('div.container', [\n        h('h1', text)\n      ])\n    );\n\n  return {\n    DOM: vtree$,\n    HTTP: request$\n  };\n}\n```\n\nSelect all the responses for a certain key:\n\n```js\nfunction main({ DOM, HTTP }) {\n  const HELLO_URL = 'http://localhost:8080/hello';\n  const request$ = Rx.Observable.just({\n    key: 'hello',\n    url: HELLO_URL\n  });\n  const vtree$ = HTTP\n    .byKey('hello')\n    .mergeAll()\n    .flatMap(res =\u003e res.text()) // We expect this to be \"Hello World\"\n    .startWith('Loading...')\n    .map(text =\u003e\n      h('div.container', [\n        h('h1', text)\n      ])\n    );\n\n  return {\n    DOM: vtree$,\n    HTTP: request$\n  };\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyclejs%2Fcycle-fetch-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyclejs%2Fcycle-fetch-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyclejs%2Fcycle-fetch-driver/lists"}