{"id":16419230,"url":"https://github.com/kokororin/honoka","last_synced_at":"2025-09-11T17:39:53.970Z","repository":{"id":39787851,"uuid":"100004550","full_name":"kokororin/honoka","owner":"kokororin","description":"Just a fetch() API wrapper for both Browser and Node.js.","archived":false,"fork":false,"pushed_at":"2023-01-06T01:56:25.000Z","size":2666,"stargazers_count":9,"open_issues_count":18,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T07:16:13.471Z","etag":null,"topics":["fetch","fetch-api","fetch-polyfill"],"latest_commit_sha":null,"homepage":"","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/kokororin.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":"2017-08-11T07:25:39.000Z","updated_at":"2022-06-21T15:52:30.000Z","dependencies_parsed_at":"2023-02-05T02:16:58.543Z","dependency_job_id":null,"html_url":"https://github.com/kokororin/honoka","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokororin%2Fhonoka","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokororin%2Fhonoka/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokororin%2Fhonoka/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokororin%2Fhonoka/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kokororin","download_url":"https://codeload.github.com/kokororin/honoka/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811374,"owners_count":16884305,"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":["fetch","fetch-api","fetch-polyfill"],"created_at":"2024-10-11T07:16:23.012Z","updated_at":"2024-10-28T09:16:27.661Z","avatar_url":"https://github.com/kokororin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# honoka\n\n[![npm version](https://img.shields.io/npm/v/honoka.svg)](https://www.npmjs.org/package/honoka)\n[![Build Status](https://travis-ci.org/kokororin/honoka.svg?branch=master)](https://travis-ci.org/kokororin/honoka)\n[![Coverage Status](https://coveralls.io/repos/github/kokororin/honoka/badge.svg?branch=master)](https://coveralls.io/github/kokororin/honoka?branch=master)\n\nJust a fetch() API wrapper for both Browser and Node.js.\n\n## Features\n\n- Same as [fetch() API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)\n- Timeout\n- Interceptors before request and response\n- Transform/convert request and response\n\n## Installing\n\nUsing npm:\n\n```bash\n$ npm install honoka\n```\n\nUsing cdn:\n\n```html\n\u003cscript src=\"https://unpkg.com/honoka/lib/honoka.min.js\"\u003e\u003c/script\u003e\n```\n\n## Example\n\nPerforming a `GET` request\n\n```js\n// Make a request for a user with a given ID\nhonoka.get('/user?ID=12345')\n  .then(response =\u003e {\n    console.log(response);\n    console.log(response.data);\n  })\n  .catch(error =\u003e {\n    console.log(error);\n  });\n\n// Optionally the request above could also be done as\nhonoka.get('/user', {\n    data: {\n      ID: 12345\n    }\n  })\n  .then(response =\u003e {\n    console.log(response);\n    console.log(response.data);\n  })\n  .catch(error =\u003e {\n    console.log(error);\n  });\n```\n\nPerforming a `POST` request\n\n```js\nhonoka.post('/user', {\n    data: {\n      firstName: 'Fred',\n      lastName: 'Flintstone'\n    }\n  })\n  .then(response =\u003e {\n    console.log(response);\n    console.log(response.data);\n  })\n  .catch(error =\u003e {\n    console.log(error);\n  });\n```\n\n## honoka API\n\nRequests can be made by passing the relevant config to `honoka`.\n\n##### honoka(options)\n\n```js\n// Send a POST request\nhonoka('/user/12345', {\n  method: 'post',\n  data: {\n    firstName: 'Fred',\n    lastName: 'Flintstone'\n  }\n});\n```\n\n##### honoka(url[, options])\n\n```js\n// Send a GET request (default method)\nhonoka('/user/12345');\n```\n\n### Request method aliases\n\nFor convenience aliases have been provided for all supported request methods.\n\n##### honoka.get(url[, options])\n##### honoka.delete(url[, options])\n##### honoka.head(url[, options])\n##### honoka.options(url[, options])\n##### honoka.post(url[, options])\n##### honoka.put(url[, options])\n##### honoka.patch(url[, options])\n\n## Request Config\n\nThese are the available config options for making requests. Same as fetch() API.\n\n```js\n{\n  // `method` is the request method to be used when making the request\n  method: 'get', // default\n\n  // `headers` are custom headers to be sent\n  headers: {'X-Requested-With': 'XMLHttpRequest'},\n\n  // `data` are the URL parameters or post body to be sent\n  data: {\n    ID: 12345\n  },\n\n  // `baseURL` will be prepended to `url` unless `url` is absolute.\n  baseURL: 'https://some-domain.com/api/',\n\n  // `timeout` specifies the number of milliseconds before the request times out.\n  // If the request takes longer than `timeout`, the request will be aborted.\n  timeout: 1000,\n\n  // `dataType` indicates the type of data that the server will respond with\n  // options are 'arraybuffer', 'blob', 'buffer', 'json', 'text', 'auto'\n  dataType: 'auto', // default\n\n  // Authentication credentials mode\n  // https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials\n  credentials: 'omit', // default\n\n\n  // `expectedStatus` defines whether to resolve or reject the promise for a given\n  // HTTP response status code. If `expectedStatus` returns `true` (or is set to `null`\n  // or `undefined`), the promise will be resolved; otherwise, the promise will be\n  // rejected.\n  expectedStatus(status) {\n    return status \u003e= 200 \u0026\u0026 status \u003c 400; // default\n  },\n\n  // to ignore interceptors for one request\n  ignoreInterceptors: false,\n}\n```\n\n## Config Defaults\n\nYou can specify config defaults that will be applied to every request.\n\n### Global Defaults\n\n```js\nhonoka.defaults.baseURL = 'https://example.com/api';\nhonoka.defaults.timeout = 10e3;\nhonoka.defaults.method = 'get';\nhonoka.defaults.headers.post['Content-Type'] = 'application/json';\n```\n\n## Interceptors\nYou can intercept requests or responses before they are handled by `then`.\n\n```js\nconst unregister = honoka.interceptors.register({\n  request: options =\u003e {\n    // Modify the options here\n    const token = localStorage.getItem('token');\n    if (token) {\n      options.headers['X-JWT-Token'] = token;\n    }\n    return options;\n  },\n  response: response =\u003e {\n    // Check responseData here\n    if (response.data.status \u0026\u0026 response.data.status !== 'success') {\n      return new Error(response.data.message);\n    }\n    // Modify the response object\n    return response;\n  }\n})\n\n// Unregister your interceptor\nunregister();\n```\n\n## Abort Operation\n\nYou can cancel a pending request manually by using `AbortController`.\n\n```js\nlet abortController = new AbortController(),\n    signal = abortController.signal;\n\nhonoka('/100MBtest.bin', { signal })\n  .then((res) =\u003e {\n    console.log(res)\n  })\n  .catch((err) =\u003e {\n    console.log(err);\n  });\n\nsetTimeout(() =\u003e {\n  abortController.abort();\n}, 2000);\n```\n\n## Promises \n\nhonoka depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises).  \nIf your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).\n\n## TypeScript\n\nhonoka includes [TypeScript](http://typescriptlang.org) definitions.\n```typescript\nimport honoka from 'honoka';\nhonoka.get('/user?ID=12345');\n```\n\n## Changelog\n\nFor changelogs, see [Release Notes](https://github.com/kokororin/honoka/releases).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokororin%2Fhonoka","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkokororin%2Fhonoka","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokororin%2Fhonoka/lists"}