{"id":24983720,"url":"https://github.com/posthtml/posthtml-fetch","last_synced_at":"2025-04-11T20:52:34.382Z","repository":{"id":38844421,"uuid":"251702299","full_name":"posthtml/posthtml-fetch","owner":"posthtml","description":"PostHTML plugin for fetching and displaying remote content.","archived":false,"fork":false,"pushed_at":"2025-04-11T15:43:29.000Z","size":1397,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T20:52:27.987Z","etag":null,"topics":["api","fetch","get","got","posthtml","posthtml-plugin","remote-content"],"latest_commit_sha":null,"homepage":"","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/posthtml.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"posthtml","open_collective":"posthtml","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://mailviews.com"]}},"created_at":"2020-03-31T18:55:49.000Z","updated_at":"2025-04-05T10:29:08.000Z","dependencies_parsed_at":"2024-11-05T21:37:12.496Z","dependency_job_id":null,"html_url":"https://github.com/posthtml/posthtml-fetch","commit_stats":{"total_commits":147,"total_committers":5,"mean_commits":29.4,"dds":0.5782312925170068,"last_synced_commit":"611f8deeab95fb13091bd180332a81f189a42294"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-fetch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480515,"owners_count":21110936,"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","fetch","get","got","posthtml","posthtml-plugin","remote-content"],"created_at":"2025-02-04T09:20:45.903Z","updated_at":"2025-04-11T20:52:34.353Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003cimg width=\"150\" height=\"150\" title=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\"\u003e\r\n  \u003ch1\u003eFetch Content\u003c/h1\u003e\r\n  \u003cp\u003eA plugin for fetching and working with remote and local content\u003c/p\u003e\r\n\r\n  [![Version][npm-version-shield]][npm]\r\n  [![Build][github-ci-shield]][github-ci]\r\n  [![License][license-shield]][license]\r\n  [![Downloads][npm-stats-shield]][npm-stats]\r\n\u003c/div\u003e\r\n\r\n## About\r\n\r\nThis plugin allows you to fetch remote or local content and display it in your HTML.\r\n\r\nInput:\r\n\r\n```hbs\r\n\u003cfetch url=\"https://jsonplaceholder.typicode.com/users/1\"\u003e\r\n  {{ response.name }}'s username is {{ response.username }}\r\n\u003c/fetch\u003e\r\n```\r\n\r\nOutput:\r\n\r\n```html\r\nLeanne Graham's username is Bret\r\n```\r\n\r\n## Install\r\n\r\n```\r\nnpm i posthtml posthtml-fetch\r\n```\r\n\r\n## Usage\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch())\r\n  .process('\u003cfetch url=\"https://example.test\"\u003e{{ response }}\u003c/fetch\u003e')\r\n  .then(result =\u003e console.log(result.html))\r\n\r\n  // =\u003e interpolated response body\r\n```\r\n\r\nThe response body will be available under the `response` local variable.\r\n\r\n## Response types\r\n\r\nThe plugin supports `json` and `text` responses. \r\n\r\nOnly the response body is returned.\r\n\r\n## Expressions\r\n\r\nThe plugin uses [`posthtml-expressions`](https://github.com/posthtml/posthtml-expressions), so you can use any of its tags to work with the `response`.\r\n\r\nFor example, you can iterate over items in a JSON response:\r\n\r\n```hbs\r\n\u003cfetch url=\"https://jsonplaceholder.typicode.com/users\"\u003e\r\n  \u003ceach loop=\"user in response\"\u003e\r\n    {{ user.name }}\r\n  \u003c/each\u003e\r\n\u003c/fetch\u003e\r\n```\r\n\r\n## Options\r\n\r\nYou may configure the plugin with the following options.\r\n\r\n### `tags`\r\n\r\nType: `String[]`\\\r\nDefault: `['fetch', 'remote']`\r\n\r\nArray of supported tag names. \r\n\r\nOnly tags from this array will be processed by the plugin.\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    tags: ['get']\r\n  }))\r\n  .process('\u003cget url=\"https://example.test\"\u003e{{ response }}\u003c/get\u003e')\r\n  .then(result =\u003e console.log(result.html))\r\n```\r\n\r\n### `attribute`\r\n\r\nType: `String`\\\r\nDefault: `'url'`\r\n\r\nString representing attribute name containing the URL to fetch.\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    attribute: 'from'\r\n  }))\r\n  .process('\u003cfetch from=\"https://example.test\"\u003e{{ response }}\u003c/fetch\u003e')\r\n  .then(result =\u003e {\r\n    console.log(result.html) // interpolated response body\r\n  })\r\n```\r\n\r\n### `ofetch`\r\n\r\nThe plugin uses [`ofetch`](https://unjs.io/packages/ofetch) to fetch data. You can pass options directly to it, inside the `ofetch` object.\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    ofetch: {\r\n      // pass options to ofetch...\r\n    }\r\n  }))\r\n  .process('\u003cfetch url=\"https://example.test\"\u003e{{ response }}\u003c/fetch\u003e')\r\n  .then(result =\u003e {\r\n    console.log(result.html) // interpolated response body\r\n  })\r\n```\r\n\r\n### `preserveTag`\r\n\r\nType: `Boolean`\\\r\nDefault: `false`\r\n\r\nWhen set to `true`, this option will preserve the `tag` around the response body.\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    preserveTag: true\r\n  }))\r\n  .process('\u003cfetch url=\"https://example.test\"\u003e{{ response }}\u003c/fetch\u003e')\r\n  .then(result =\u003e {\r\n    console.log(result.html)\r\n    // =\u003e \u003cfetch url=\"https://example.test\"\u003einterpolated response body\u003c/fetch\u003e\r\n  })\r\n```\r\n\r\n### `expressions`\r\n\r\nType: `Object`\\\r\nDefault: `{}`\r\n\r\nYou can pass options to `posthtml-expressions`.\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    expressions: {\r\n      delimiters: ['[[', ']]'],\r\n    }\r\n  }))\r\n  .process('\u003cfetch url=\"https://example.test\"\u003e[[ response ]]\u003c/fetch\u003e')\r\n  .then(result =\u003e {\r\n    console.log(result.html) // interpolated response body\r\n  })\r\n```\r\n\r\n## Plugins\r\n\r\n### `after/before`\r\n\r\nList of plugins that will be called after/before receiving and processing `locals`\r\n\r\nExample:\r\n\r\n```js\r\nconst posthtml = require('posthtml')\r\nconst posthtmlFetch = require('posthtml-fetch')\r\n\r\nposthtml()\r\n  .use(posthtmlFetch({\r\n    plugins: {\r\n      before: [\r\n        tree =\u003e {\r\n          // Your plugin implementation\r\n        },\r\n        tree =\u003e {\r\n          // Your plugin implementation\r\n        }\r\n      ],\r\n      after: [\r\n        tree =\u003e {\r\n          // Your plugin implementation\r\n        },\r\n        tree =\u003e {\r\n          // Your plugin implementation\r\n        }\r\n      ]\r\n    }\r\n  }))\r\n  .process('\u003cfetch url=\"https://example.test\"\u003e{{ response }}\u003c/fetch\u003e')\r\n  .then(result =\u003e {\r\n    console.log(result.html) // interpolated response body\r\n  })\r\n```\r\n\r\n[npm]: https://www.npmjs.com/package/posthtml-fetch\r\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-fetch.svg\r\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-fetch\r\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-fetch.svg\r\n[github-ci]: https://github.com/posthtml/posthtml-fetch/actions\r\n[github-ci-shield]: https://github.com/posthtml/posthtml-fetch/actions/workflows/nodejs.yml/badge.svg\r\n[license]: ./license\r\n[license-shield]: https://img.shields.io/npm/l/posthtml-fetch.svg\r\n","funding_links":["https://patreon.com/posthtml","https://opencollective.com/posthtml","https://mailviews.com"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-fetch/lists"}