{"id":18468154,"url":"https://github.com/wearelucid/api-fetcher","last_synced_at":"2025-04-08T10:32:21.919Z","repository":{"id":24820606,"uuid":"102489878","full_name":"wearelucid/api-fetcher","owner":"wearelucid","description":"Generates multiple JSON files from fetching API endpoints (i18n supported) 🛬","archived":false,"fork":false,"pushed_at":"2023-01-05T08:22:18.000Z","size":502,"stargazers_count":5,"open_issues_count":10,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T10:51:10.494Z","etag":null,"topics":["api-fetcher","json-files","wordpress"],"latest_commit_sha":null,"homepage":null,"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/wearelucid.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-09-05T14:14:31.000Z","updated_at":"2022-10-06T12:09:35.000Z","dependencies_parsed_at":"2023-01-14T08:00:13.519Z","dependency_job_id":null,"html_url":"https://github.com/wearelucid/api-fetcher","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearelucid%2Fapi-fetcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearelucid%2Fapi-fetcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearelucid%2Fapi-fetcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wearelucid%2Fapi-fetcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wearelucid","download_url":"https://codeload.github.com/wearelucid/api-fetcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247824092,"owners_count":21002205,"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":["api-fetcher","json-files","wordpress"],"created_at":"2024-11-06T10:05:09.606Z","updated_at":"2025-04-08T10:32:21.501Z","avatar_url":"https://github.com/wearelucid.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Api fetcher\n\n[![npm version](https://img.shields.io/npm/v/@wearelucid/api-fetcher.svg?style=flat-square)](https://www.npmjs.com/package/@wearelucid/api-fetcher)\n\nGenerates multiple JSON files from fetching (WordPress) API endpoints (i18n supported) 🚀\n\n## Installation\n```bash\nyarn add @wearelucid/api-fetcher\n```\n\n## Usage\nBe aware that this package uses ES6 syntax!\n\nAdd a script to your package.json\n```JSON\n\"scripts\": {\n  \"fetch\": \"node fetchData.js\"\n}\n```\nSince node currently does not support es2015 module syntax, we need to install [`babel-cli`](https://yarnpkg.com/en/package/babel-cli) and add the script like so:\n```JSON\n\"scripts\": {\n  \"fetch\": \"babel-node --presets env -- fetchData.js\"\n}\n```\n\n```bash\nyarn fetch\n```\n\n## Example\n\n### Full Example (Wordpress)\n\n```javascript\nimport fetcher from 'api-fetcher'\n\nconst config = {\n  savePath: './static/data',\n  compressJSON: true, // setting this to false may help debugging :-)\n  perPage: 5000, // arbitrary\n  itemsPerPage: 10, // set for pagination (default will automatically be 10)\n  languages: [\n    { lang: 'de', locale: 'de_CH' },\n    { lang: 'en', locale: 'en_US' }\n  ],\n  apiUrl: 'https://your-backend/api'\n}\n\nfetcher.log.printText('Lucid')\nfetcher.log.printConfig(config)\n\n// fetch paginated posts\nfetcher.paginate('posts', { posts: { method: fetcher.getWPPostType, postType: 'posts', transforms: [removeFieldsFromPost] } },\n\n// fetch bundled data\nfetcher.bundle('basic', {\n  pages: { method: fetcher.getWPPostType, postType: 'pages', transforms: [removeFieldsFromPost, decodeTitle], filters: [showOnlyPublished] },\n  menus: { method: fetcher.getWPMenus },\n  options: { method: fetcher.getWPOptionsPage, slug: 'options' },\n\n  // If you need to get categories and custom taxonomies\n  categories: { method: fetcher.getWPCategories },\n  formats: { method: fetcher.getWPCustomTaxonomy, taxonomy: 'formats' }\n}, config)\n\n\n/**\n* Filter (Note: This filter is an example. It is not needed. Wordpress by default only delivers published posts and pages)\n*/\nfunction showOnlyPublished (data) {\n  return (data \u0026\u0026 data.length) ? data.filter(p =\u003e p.status === 'publish') : data\n}\n\n/**\n* Delete fields we don't need (anymore)\n*/\nfunction removeFieldsFromPost (data) {\n  return fetcher.applyToOneOrMany(_removeFieldsFromPost, data)\n}\n\nfunction _removeFieldsFromPost (data) {\n  delete data._links\n  return data\n}\n```\n\n### Generating Multiple Bundles\nIf you want to generate multiple json bundles you can invoke `fetcher.bundle()` with different a name like so:\n```javascript\nfetcher.bundle('basic', {\n  pages: { method: fetcher.getWPPostType, postType: 'pages', transforms: [removeFieldsFromPost, decodeTitle] },\n  posts: { method: fetcher.getWPPostType, postType: 'posts', transforms: [removeFieldsFromPost, decodeTitle] }\n}, config)\n```\n\n### Generating Paginated Collections\nYou can also generated paginated collections like so:\n```javascript\nfetcher.paginate('posts', { posts: { method: fetcher.getWPPostType, postType: 'posts', transforms: [removeFieldsFromPost, decodeTitle] } }, config)\nfetcher.paginate('pages', { pages: { method: fetcher.getWPPostType, postType: 'pages', transforms: [removeFieldsFromPost, decodeTitle] } }, config)\n```\n\nIn some cases you might also want to load all items of the once you loaded paginated (for having all the data):\n```javascript\nfetcher.bundle('fileName', { posts: { method: fetcher.getWPPostType, postType: 'posts', transforms: [removeFieldsFromPost, decodeTitle] } }, config)\n```\n\nDefault items per page will be set to `10`.\nYou can provide the variable `itemsPerPage` inside your config.\n```\nitemsPerPage: 10\n```\n\nThis will generate a collection of json files (with your specified naming), in this case:\n```bash\nposts.de.1.json\nposts.de.2.json\nposts.de.3.json\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearelucid%2Fapi-fetcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwearelucid%2Fapi-fetcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwearelucid%2Fapi-fetcher/lists"}