{"id":15626056,"url":"https://github.com/typicode/fetchival","last_synced_at":"2025-05-16T13:05:23.332Z","repository":{"id":30744886,"uuid":"34301319","full_name":"typicode/fetchival","owner":"typicode","description":"Easy window.fetch requests","archived":false,"fork":false,"pushed_at":"2018-12-06T06:35:21.000Z","size":69,"stargazers_count":521,"open_issues_count":19,"forks_count":32,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-03T09:11:12.203Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/typicode.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":"2015-04-21T03:15:29.000Z","updated_at":"2025-01-28T22:18:54.000Z","dependencies_parsed_at":"2022-09-06T20:52:51.410Z","dependency_job_id":null,"html_url":"https://github.com/typicode/fetchival","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Ffetchival","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Ffetchival/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Ffetchival/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Ffetchival/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typicode","download_url":"https://codeload.github.com/typicode/fetchival/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248544039,"owners_count":21121882,"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-10-03T10:09:52.411Z","updated_at":"2025-04-12T09:21:51.224Z","avatar_url":"https://github.com/typicode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetchival.js [![Travis](https://img.shields.io/travis/typicode/fetchival.svg)](https://travis-ci.org/typicode/fetchival)\n\n\u003e Makes writing JSON requests with [fetch](https://github.com/github/fetch) easier\n\nFetchival is a tiny (0.5kb min/gz) fetch wrapper that can be used in the __browser__ (IE9+) and __Node__.\n\n__Before__\n\n```javascript\n// POST /users\nfetch('/users', {\n  method: 'post',\n  headers: {\n    'Accept': 'application/json',\n    'Content-Type': 'application/json'\n  },\n  body: JSON.stringify({\n    name: 'Typicode',\n    login: 'typicode',\n  })\n})\n.then(function(response) {\n  if (response.status \u003e= 200 \u0026\u0026 response.status \u003c 300) {\n    return response.json()\n  }\n  throw new Error(response.statusText)\n})\n.then(function(json) {\n  // ...\n})\n```\n\n__After__\n\n```javascript\n// POST /users\nfetchival('/users').post({\n  name: 'Typicode',\n  login: 'typicode'\n})\n.then(function(json) {\n  // ...\n})\n```\n\n`.get()`, `.put()`, `.patch()` and `.delete()` methods are also available.\n\n## Installation\n\nFetchival is available on Bower and npm\n\n__Browser__\n\n```bash\nbower install es6-promise fetch # polyfills\nbower install fetchival\n```\n\n```bash\nnpm install es6-promise whatwg-fetch --save # polyfills\nnpm install fetchival --save # Browserify\n```\n\n__Node__\n\n```bash\nnpm install node-fetch fetchival --save\n```\n\n## Usage examples\n\n```javascript\nvar posts = fetchival('/posts')\n\n//posts\nposts.get()\nposts.post({ title: 'Fetchival' })\n\n//posts?category=javascript\nposts.get({ category: 'javascript' })\n\n//posts/1\nposts(1).get()\nposts(1).put({ title: 'Fetchival is simple' })\nposts(1).patch({ title: 'Fetchival is simple' })\nposts(1).delete()\n\nvar comments = posts('1/comments')\n\n//posts/1/comments\ncomments.get()\n\n//posts/1/comments/1\ncomments(1).get()\n```\n\nYou can also pass fetch options to `fetchival()`\n\n```javascript\nvar posts = fetchival('/posts', fetchOptions)\nvar comments = posts('1/comments') // Will inherit fetchOptions\n```\n\nTo catch errors\n\n```javascript\nfetchival('/posts')\n  .get()\n  .catch(function(err) {\n    console.log(err)\n  })\n```\n\nTo enable CORS\n\n```javascript\nvar request = fetchival('/', { mode: 'cors' })\nvar posts = request('posts')\n```\n\nTo fetch plain text (for example, HTML views)\n\n```javascript\nvar request = fetchival('/', { responseAs: 'text' })\nvar posts = request('posts')\n```\n\n`responseAs` can be `response`, `text` or `json` (default)\n\nTo use fetchival in Node, you need to install `node-fetch` and configure fetchival to use it\n\n```javascript\nvar fetchival = require('fetchival')\nfetchival.fetch = require('node-fetch')\n```\n\n## Browser Support\n\n![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png)\n--- | --- | --- | --- | --- |\nLatest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | 6.1+ ✔ |\n\n## License\n\nMIT - [Typicode](https://github.com/typicode)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicode%2Ffetchival","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypicode%2Ffetchival","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicode%2Ffetchival/lists"}