{"id":17291318,"url":"https://github.com/cxres/prep-fetch","last_synced_at":"2026-07-10T15:32:53.526Z","repository":{"id":247785245,"uuid":"825972056","full_name":"CxRes/prep-fetch","owner":"CxRes","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-20T01:24:07.000Z","size":76,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-02T18:13:26.150Z","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":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CxRes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-08T21:31:03.000Z","updated_at":"2024-10-31T23:04:10.000Z","dependencies_parsed_at":"2024-07-10T16:17:29.280Z","dependency_job_id":"b3db1100-00c0-43e0-a749-b99d398f0a42","html_url":"https://github.com/CxRes/prep-fetch","commit_stats":null,"previous_names":["cxres/prep-fetch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CxRes/prep-fetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CxRes%2Fprep-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CxRes%2Fprep-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CxRes%2Fprep-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CxRes%2Fprep-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CxRes","download_url":"https://codeload.github.com/CxRes/prep-fetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CxRes%2Fprep-fetch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35335897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-10T02:00:06.465Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-15T10:40:43.435Z","updated_at":"2026-07-10T15:32:53.510Z","avatar_url":"https://github.com/CxRes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PREP Fetch\n\nPrep your [`Fetch`](https://fetch.spec.whatwg.org/) [`Response`](https://fetch.spec.whatwg.org/#responses) to receive [Per Resource Events](https://cxres.github.io/prep/draft-gupta-httpbis-per-resource-events.html) notifications.\n\nPREP Fetch is thin wrapper around [Multipart Fetch](https://npmjs.com/package/multipart-fetch) that pre-processes the response to a PREP request giving you separate representation and notification streams.\n\n## Installation\n\n### Browser\n\nYou can use PREP Fetch directly in the browser as shown below:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import prepFetch from \"https://path/to/prep-fetch/dist/browser.js\";\n\u003c/script\u003e\n```\n\n#### CDN\n\nReplace the dummy import path with a link to the bundle provided by your favourite CDN. Find the links/link formats at:\n\n- [jsdelivr](https://www.jsdelivr.com/package/npm/prep-fetch)\n- [unpkg](https://www.unpkg.com/)\n\n#### Local\n\nAlternatively you can download the package from npm and use it locally. If you have npm installed, an easy way to do this is:\n\n```sh\nnpm pack prep-fetch\n```\n\nUnpack the downloaded `.tgz` file and point the import path to `dist/browser.min.js`.\n\n### JavaScript Runtimes\n\nInstall PREP Fetch using your favorite package manager:\n\n```sh\n\u003cnpm|pnpm|yarn|bun\u003e add prep-fetch\n```\n\nYou can now `import` PREP Fetch in your project, as usual:\n\n```js\nimport prepFetch from \"prep-fetch\";\n```\n\nOn Deno, you can link to the bundle directly from source, just like in the browser, or export it from `deps.ts`.\n\n## Usage\n\n1. Request PREP notifications using `Fetch` and invoke PREP Fetch on the response:\n\n   ```js\n   let response;\n   try {\n     response = await fetch(\"https://example.org/source/of/events\", {\n       headers: {\n         \"accept-events\": '\"prep\"',\n       },\n     });\n   } catch (error) {\n     // Handle any network errors\n   }\n\n   const prepResponse = prepFetch(response);\n   ```\n\n2. Read representation, say, as text:\n\n   ```js\n   const representation = await prepResponse.getRepresentation();\n   console.log(await representation.text());\n   ```\n\n   **IMPORTANT**: Read the representation completely before reading notifications as these are being delivered serially on the underlying HTTP response stream.\n\n3. Now get the notifications and iterate over it:\n\n   ```js\n   const notifications = await prepResponse.getNotifications();\n   for await (const notification of notifications) {\n     // .message parses the Response body as a internet format message\n     // mime-type: `message/rfc822`\n     const message = await notification.message();\n     // output the notification\n     console.log(message.headers);\n     // output any body\n     console.log(await message.body());\n   }\n   ```\n\n   or, if you are using the asyncIterator protocol:\n\n   ```js\n   const notifications = await prepResponse.getNotifications();\n   const notificationsIterator = notifications.notifications();\n   let { value, done } = await notificationsIterator.next();\n   while (!done) {\n     const message = await notification.message();\n     console.log(await message.body());\n     ({ value, done } = await notificationsIterator.next());\n   }\n   ```\n\n   **IMPORTANT**: Always read each message completely before proceeding to the next notification.\n\nFor a more detailed example, see the \"should serve notifications\" block in `tests/integration/prep-fetch.test.js`.\n\n## Copyright and License\n\nCopyright © 2024, [Rahul Gupta](https://cxres.pages.dev/profile#i) and PREP Fetch contributors.\n\nThe source code in this repository is released under the [Mozilla Public License v2.0](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxres%2Fprep-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxres%2Fprep-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxres%2Fprep-fetch/lists"}