{"id":17774815,"url":"https://github.com/rickwong/fetch-plus","last_synced_at":"2025-04-03T02:12:04.988Z","repository":{"id":57120070,"uuid":"46756440","full_name":"RickWong/fetch-plus","owner":"RickWong","description":"🐕 Fetch API with middlewares","archived":false,"fork":false,"pushed_at":"2020-08-18T04:19:15.000Z","size":643,"stargazers_count":119,"open_issues_count":30,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T13:05:23.421Z","etag":null,"topics":["ajax","csrf","fetch","fetch-plus","http","immutablejs","isomorphic","json","nodejs","promises","rest","user-agent","xml"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RickWong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-24T00:21:55.000Z","updated_at":"2024-06-20T07:45:17.000Z","dependencies_parsed_at":"2022-08-24T04:31:45.546Z","dependency_job_id":null,"html_url":"https://github.com/RickWong/fetch-plus","commit_stats":null,"previous_names":["rickwong/fetch-rest"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickWong%2Ffetch-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickWong%2Ffetch-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickWong%2Ffetch-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RickWong%2Ffetch-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RickWong","download_url":"https://codeload.github.com/RickWong/fetch-plus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922248,"owners_count":20855345,"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":["ajax","csrf","fetch","fetch-plus","http","immutablejs","isomorphic","json","nodejs","promises","rest","user-agent","xml"],"created_at":"2024-10-26T21:52:22.959Z","updated_at":"2025-04-03T02:12:04.968Z","avatar_url":"https://github.com/RickWong.png","language":"JavaScript","readme":"# Fetch+\n\nA convenient [Fetch API](https://github.com/whatwg/fetch) library with first-class middleware support.\n\n[![version](https://img.shields.io/npm/v/fetch-plus.svg)](https://npmjs.org/package/fetch-plus) ![license](https://img.shields.io/npm/l/fetch-plus.svg) [![Package Quality](http://npm.packagequality.com/shield/fetch-plus.svg?1289194656)](http://packagequality.com/#?package=fetch-plus)  ![installs](https://img.shields.io/npm/dt/fetch-plus.svg)\n\n## Features\n\n- Drop-in replacement for fetch().\n- Simple [BREAD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) methods for consuming REST APIs.\n- A \"queries\" object option for building safe query strings more easily.\n- All options can be computed values: `myHeaders: () =\u003e values`\n- Custom middlewares to manipute requests, responses, and caught errors.\n- Useful middlewares and handlers (JSON/Auth/CSRF/Immutable etc) available as separate npm packages.\n- [Fetch API Streams draft](https://github.com/yutakahirano/fetch-with-streams) handler with an Observable interface.\n- Runs in Node and all browsers.\n\n## Installation\n\n```bash\nnpm install --save fetch-plus  isomorphic-fetch\n```\n\n## Additional middlewares\n\n```bash\nnpm install --save fetch-plus-basicauth\nnpm install --save fetch-plus-bearerauth\nnpm install --save fetch-plus-csrf\nnpm install --save fetch-plus-immutable\nnpm install --save fetch-plus-json\nnpm install --save fetch-plus-oauth\nnpm install --save fetch-plus-stream\nnpm install --save fetch-plus-useragent\nnpm install --save fetch-plus-xml\n```\n\n## Usage\n\n**import/require**\n\n```js\nimport {fetch, createClient} from \"fetch-plus\";\n```\n\n**fetch**\n\n```js\nfetch(\"http://some.api.example/v1\", {\n\tquery: {foo: \"bar\"},                // Query string object. So convenient.\n\tbody: () =\u003e \"R2-D2\"                 // Computed values are computed.\n});\n```\n\n**createClient**\n\nCreates a RESTful client so middlewares can be added to it.\n\n```js\nconst client = createClient(\"http://some.api.example/v1\");\n```\n\n**client.addMiddleware**\n\nCreate middlewares like: `(request) =\u003e (response) =\u003e response`\n\n```js\nclient.addMiddleware(\n\t(request) =\u003e {\n\t\trequest.path += \".json\";\n\t\trequest.options.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n\n\t\treturn (response) =\u003e response.json();\n\t}\n);\n```\n\n**client.request**\n\n`request` performs generic requests to the configured endpoint.\n\n```js\nclient.request(\"posts/25/comments\", {\n\tmethod: \"POST\",\n\tbody: {comment: \"C-3PO\"}\n});\n```\n\n**client.browse|read|edit|add|destroy|replace**\n\nBREAD helpers that perform requests to the configured endpoint.\n\n```js\nclient.browse(            \n\t\"posts\"                    // A string...\n);\n\nclient.add(\n\t[\"posts\", 1, \"comments\"],  // ...or an array like [\"posts\", id, \"comments\"]\n\t{body: \"C-3PO\"}            // Regular Fetch API body option.\n);\n```\n\n**client.list|create|read|update|destroy**\n\nCRUD aliases that perform requests to the configured endpoint.\n\n```js\nclient.list(            \n\t\"posts\"                    // A string...\n);\n\nclient.create(\n\t[\"posts\", 1, \"comments\"],  // ...or an array like [\"posts\", id, \"comments\"]\n\t{body: \"C-3PO\"}            // Regular Fetch API body option.\n);\n```\n\n**handlers**\n\nHandlers take configuration and return functions to pass to `.then()`.\n\n```js\n// Transform JSON with fetch-plus-json.\nimport plusJson from \"fetch-plus-json\";\n\nfetch(\"http://some.api.example/v1/posts\").then(plusJson.handler({some:\"config\"}));\n```\n\nSee [example](https://github.com/RickWong/fetch-plus/blob/master/example/src/index.js) for more.\n\n## Community\n\nLet's start one together! After you ★Star this project, follow me [@Rygu](https://twitter.com/rygu)\non Twitter.\n\n## License\n\nBSD 3-Clause license. Copyright © 2015, Rick Wong. All rights reserved.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickwong%2Ffetch-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frickwong%2Ffetch-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frickwong%2Ffetch-plus/lists"}