{"id":13453788,"url":"https://github.com/sindresorhus/ky-universal","last_synced_at":"2025-05-15T02:09:32.894Z","repository":{"id":37617095,"uuid":"172099953","full_name":"sindresorhus/ky-universal","owner":"sindresorhus","description":"Use Ky in both Node.js and browsers","archived":false,"fork":false,"pushed_at":"2023-09-01T21:26:23.000Z","size":30,"stargazers_count":674,"open_issues_count":2,"forks_count":20,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-02T23:28:22.109Z","etag":null,"topics":["browser","fetch","http-client","http-request","isomorphic","nodejs","npm-package","request","ssr","whatwg-fetch"],"latest_commit_sha":null,"homepage":"https://github.com/sindresorhus/ky","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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2019-02-22T16:39:06.000Z","updated_at":"2025-04-13T14:45:21.000Z","dependencies_parsed_at":"2022-07-16T13:16:14.102Z","dependency_job_id":"547eb476-209d-4844-974a-0bda1c08bbb2","html_url":"https://github.com/sindresorhus/ky-universal","commit_stats":{"total_commits":46,"total_committers":8,"mean_commits":5.75,"dds":"0.17391304347826086","last_synced_commit":"4f3f576c55a19dc13dd52c593e146ed384666927"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fky-universal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fky-universal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fky-universal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fky-universal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/ky-universal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252849484,"owners_count":21813816,"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":["browser","fetch","http-client","http-request","isomorphic","nodejs","npm-package","request","ssr","whatwg-fetch"],"created_at":"2024-07-31T08:00:47.344Z","updated_at":"2025-05-15T02:09:32.864Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","包","Helper Components"],"sub_categories":["HTTP"],"readme":"# ky-universal\n\n\u003e Use Ky in both Node.js and browsers\n\n**As of [Ky 1.0.0](https://github.com/sindresorhus/ky/releases/tag/v1.0.0), it runs natively on Node.js. So this package is no longer needed.**\n\n[Ky](https://github.com/sindresorhus/ky) is made for browsers, but this package makes it possible to use it in Node.js too, by polyfilling most of the required browser APIs using [`node-fetch`](https://github.com/bitinn/node-fetch).\n\nThis package can be useful for:\n- Isomorphic code\n- Web apps (React, Vue.js, etc.) that use server-side rendering (SSR)\n- Testing browser libraries using a Node.js test runner\n\n**Note:** Before opening an issue, make sure it's an issue with Ky and not its polyfills. Generally, if something works in the browser, but not in Node.js, it's an issue with `node-fetch`.\n\nKeep in mind that Ky targets [modern browsers](https://github.com/sindresorhus/ky#browser-support) when used in the browser. For older browsers, you will need to transpile and use a [`fetch` polyfill](https://github.com/github/fetch).\n\n## Install\n\n```sh\nnpm install ky ky-universal\n```\n\n*Note that you also need to install `ky`.*\n\n## Usage\n\n```js\nimport ky from 'ky-universal';\n\nconst parsed = await ky('https://httpbin.org/json').json();\n\n// …\n```\n\n## `ReadableStream` support\n\nFor [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) support, also install [`web-streams-polyfill`](https://github.com/MattiasBuelens/web-streams-polyfill):\n\n```\n$ npm install web-streams-polyfill\n```\n\nYou can then use it normally:\n\n```js\nimport ky from 'ky-universal';\n\nconst {body} = await ky('https://httpbin.org/bytes/16');\nconst {value} = await body.getReader().read();\nconst result = new TextDecoder('utf-8').decode(value);\n\n// …\n```\n\n## API\n\nThe API is exactly the same as the [Ky API](https://github.com/sindresorhus/ky#api), including the [named exports](https://github.com/sindresorhus/ky#httperror).\n\n## FAQ\n\n#### How do I use this with a web app (React, Vue.js, etc.) that uses server-side rendering (SSR)?\n\nUse it like you would use Ky:\n\n```js\nimport ky from 'ky-universal';\n\nconst parsed = await ky('https://httpbin.org/json').json();\n\n// …\n```\n\nWebpack will ensure the polyfills are only included and used when the app is rendered on the server-side.\n\n#### How do I test a browser library that uses Ky in AVA?\n\nPut the following in package.json:\n\n```json\n{\n\t\"ava\": {\n\t\t\"require\": [\n\t\t\t\"ky-universal\"\n\t\t]\n\t}\n}\n```\n\nThe library that uses Ky will now *just work* in AVA tests.\n\n#### `clone()` hangs with a large response in Node - What should I do?\n\nStreams in Node.js have a smaller internal buffer size (16 kB, aka `highWaterMark`) than browsers (\u003e1 MB, not consistent across browsers). When using Ky, the default `highWaterMark` is set to 10 MB, so you shouldn't encounter many issues related to that.\n\nHowever, you can specify a custom `highWaterMark` if needed:\n\n```js\nimport ky from 'ky-universal';\n\nconst response = await ky('https://example.com', {\n\t// 20 MB\n\thighWaterMark: 1000 * 1000 * 20\n});\n\nconst data = await response.clone().buffer();\n```\n\n## Related\n\n- [ky](https://github.com/sindresorhus/ky) - Tiny and elegant HTTP client based on the browser Fetch API\n- [got](https://github.com/sindresorhus/got) - Simplified HTTP requests in Node.js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fky-universal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fky-universal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fky-universal/lists"}