{"id":15331761,"url":"https://github.com/adobe/ffetch","last_synced_at":"2025-04-15T03:01:26.526Z","repository":{"id":94186443,"uuid":"608114761","full_name":"adobe/ffetch","owner":"adobe","description":"Franklin wrapper for fetch","archived":false,"fork":false,"pushed_at":"2024-12-04T09:06:30.000Z","size":159,"stargazers_count":15,"open_issues_count":1,"forks_count":5,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-03-28T14:43:10.861Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adobe.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":"2023-03-01T10:56:16.000Z","updated_at":"2025-02-27T14:43:02.000Z","dependencies_parsed_at":"2024-12-04T09:23:01.718Z","dependency_job_id":"3adba4ee-098c-430a-9a5f-fd00795de51c","html_url":"https://github.com/adobe/ffetch","commit_stats":null,"previous_names":["trieloff/ffetch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adobe%2Fffetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adobe%2Fffetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adobe%2Fffetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adobe%2Fffetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adobe","download_url":"https://codeload.github.com/adobe/ffetch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997095,"owners_count":21195798,"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-01T09:56:39.852Z","updated_at":"2025-04-15T03:01:26.499Z","avatar_url":"https://github.com/adobe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `ffetch` – `fetch` for Edge Delivery Services (Franklin)\n\n`ffetch` is a small wrapper around the JavaScript `fetch` function that helps you deal with the AEM (.live) Content API when\nbuilding a composable application. It makes it easy to `fetch` content from \n[an Index](https://www.aem.live/developer/indexing), apply lazy pagination, follow links to pages, and even pull\n[page metadata](https://www.aem.live/developer/block-collection/metadata). With `ffetch` you get all the ease of creating\na headless application without the peformance baggage of headless SDKs and the complexity of headless APIs.\n\n## Why `ffetch`?\n\n- minimal: less than [200 lines of code](https://github.com/Buuhuu/ffetch/blob/main/src/ffetch.js)\n- dependency free, just copy it into your project\n- high performance: uses your browser cache\n- works in browsers and node.js\n- fun to use\n\n## Usage\n\nCheck the [tests for detailed examples](https://github.com/Buuhuu/ffetch/blob/main/test/ffetch.js):\n\n### Get Entries from an Index\n\n```javascript\nconst entries = ffetch('/query-index.json');\nlet i = 0;\nfor await (const entry of entries) {\n  console.log(entry.title);\n}\n```\n\n`ffetch` will return a generator, so you can just iterate over the return value. If pagination is necessary, `ffetch` will\nfetch additional pages from the server as you exhaust the available records.\n\n### Get the first entry\n\n```javascript\nconsole.log(await ffetch('/query-index.json').first());\n```\n\n### Get all entries as an array (so you can `.map` and `.filter`)\n\nUsing `.all()` you can change the return value from a generator to a plain array.\n\n```javascript\nconst allentries = await ffetch('/query-index.json').all();\nallentries.forEach((e) =\u003e {\n  console.log(e);\n});\n```\n\nBut if you prefer to use `.map` and `.filter`, you can do this right on the generator:\n\n```javascript\nconst someentries = ffetch('/query-index.json')\n  .map(({title}) =\u003e title)\n  .filter(title =\u003e title.indexOf('Helix'));\nfor await (title of someentries) {\n  console.log(title);\n}\n```\n\n### Tune performance with `.chunks` and `.limit`\n\nIf you want to control the size of the chunks that are loaded using pagination, use `ffetch(...).chunks(100)`.\n\nTo limit the result set based on the number of entries you need to show on the page, use `ffetch(...).limit(5)`. The `limit()`\napplies after all `.filter()`s, so it is an effective way to only process what needs to be shown.\n\nIf you need to skip a couple of entries, then `.slice(start, end)` is your friend. It works exactly like \n[`Array.prototype.slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\n\n### Work with multi-sheets\n\nAEM JSON resources can contain multiple sheets. With `.sheet(name)` you can specify, which sheet you want to access.\n\n```javascript\nconst entries = ffetch('/query-index.json')\n  .sheet('products');\nlet i = 0;\nfor await (const entry of entries) {\n  console.log(entry.sku);\n}\n```\n\n### Work with HTML pages\n\nIn AEM, the Hypertext is the API, so you can get a [Document](https://developer.mozilla.org/en-US/docs/Web/API/Document) for\neach HTML document referenced from an index sheet.\n\n```javascript\nconst docs = ffetch('/query-index.json')\n   // assumes that the path property holds the reference to our document\n   // stores the returned document in a new field (optional)\n  .follow('path', 'document')\n  .map(({document}) =\u003e document.querySelector('img')) // get the first image\n  .filter(i =\u003e !!i) // drop entries that don't have an image\n  .limit(10); // that's enough\n  \nfor await (const img of docs) {\n  document.append(img); // take the image from the linked document and place it here\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadobe%2Fffetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadobe%2Fffetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadobe%2Fffetch/lists"}