{"id":20567219,"url":"https://github.com/markmead/alpinejs-fetch","last_synced_at":"2025-09-25T23:30:48.601Z","repository":{"id":259541420,"uuid":"878168402","full_name":"markmead/alpinejs-fetch","owner":"markmead","description":"Alpine JS magic methods wrapper for fetch API methods 📨","archived":false,"fork":false,"pushed_at":"2024-10-31T14:38:21.000Z","size":10,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T04:45:43.043Z","etag":null,"topics":["alpinejs","alpinejs-plugin","fetch","fetch-api"],"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/markmead.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-10-24T22:10:23.000Z","updated_at":"2024-11-01T11:37:05.000Z","dependencies_parsed_at":"2024-10-26T10:52:29.109Z","dependency_job_id":"57e6ac15-d095-41d8-a021-23c156c2d351","html_url":"https://github.com/markmead/alpinejs-fetch","commit_stats":null,"previous_names":["markmead/alpinejs-fetch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-fetch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234267548,"owners_count":18805420,"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":["alpinejs","alpinejs-plugin","fetch","fetch-api"],"created_at":"2024-11-16T04:45:45.263Z","updated_at":"2025-09-25T23:30:43.360Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpine JS Fetch\n\nAlpine JS magic methods wrapper for fetch API methods 📨\n\n## Install\n\n### With a CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-fetch@latest/dist/api.min.js\"\n\u003e\u003c/script\u003e\n\n\u003cscript defer src=\"https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js\"\u003e\u003c/script\u003e\n```\n\n### With a Package Manager\n\n```shell\nyarn add -D alpinejs-fetch\n\nnpm install -D alpinejs-fetch\n```\n\n```js\nimport Alpine from 'alpinejs'\nimport api from 'alpinejs-fetch'\n\nAlpine.plugin(api)\n\nAlpine.start()\n```\n\n## Example\n\n### GET\n\n```html\n\u003cdiv x-data=\"{ productData: {} }\"\u003e\n  \u003cbutton @click=\"productData = await $get('https://dummyjson.com/products/1')\"\u003e\n    Get\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\n### POST\n\n```html\n\u003cdiv x-data=\"{ productData: {} }\"\u003e\n  \u003cbutton\n    @click=\"productData = await $post('https://dummyjson.com/products/add', { title: 'BMW Pencil' })\"\n  \u003e\n    Create\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\n### PUT/PATCH\n\n```html\n\u003cdiv x-data=\"{ productData: {} }\"\u003e\n  \u003c!-- You can also use $patch --\u003e\n  \u003cbutton\n    @click=\"productData = await $put('https://dummyjson.com/products/1', { title: 'iPhone Galaxy +1' })\"\n  \u003e\n    Update\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\n### DELETE\n\n```html\n\u003cdiv x-data=\"{ productData: {} }\"\u003e\n  \u003cbutton\n    @click=\"productData = await $delete('https://dummyjson.com/products/1')\"\n  \u003e\n    Delete\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\n## Filtering the Response\n\nA lot of the times you only need a property from the response object, this is\nusually `data`. You'll see/write stuff like this:\n\n_Please note, this depends on the API response and not all APIs will share the\nsame response format._\n\n```js\nconst { data } = fetch('https://dummyjson.com/products/1')\n```\n\nWith this package you can do that by adding `[data]` to the end of the URL.\n\n```html\n\u003cdiv x-data=\"{ productData: {} }\"\u003e\n  \u003c!-- Single --\u003e\n  \u003cbutton\n    @click=\"productData = await $get('https://dummyjson.com/products/1[data]')\"\n  \u003e\n    Get\n  \u003c/button\u003e\n\n  \u003c!-- Multiple --\u003e\n  \u003c!-- Comma separation is optional --\u003e\n  \u003cbutton\n    @click=\"productData = await $get('https://dummyjson.com/products/1[data, status]')\"\n  \u003e\n    Get\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\nThis works for all the requests and isn't limited to the `data` property.\nAnything that is part of the response object can be used to filter the response.\nFor example, `[status]`.\n\n_Heads up! Syntax is important, the filter property key must be place in square\nbrackets `[x]`._\n\n### Nested Filters\n\nSometimes you don't want the whole object back, in this example `data` returns a\nlot of information but we only want `title` and `price` back. Here's how you can\ndo that.\n\n```html\n\n  \u003cbutton\n    @click=\"productData = await $get('https://dummyjson.com/products/1[data.title, data.price]')\"\n  \u003e\n    Get\n  \u003c/button\u003e\n\n  \u003cpre x-text=\"JSON.stringify(productData, null, 2)\"\u003e\u003c/pre\u003e\n\u003c/div\u003e\n```\n\nThis will return with the first key, in this case `data` omitted.\n\n```json\n{\n  \"title\": \"iPhone 9\",\n  \"price\": 549\n}\n```\n\n_Note! You can still pass other filters in when using nested filters, something\nlike `[data.title, status]` will work fine!_\n\n## Stats\n\n![](https://img.shields.io/bundlephobia/min/alpinejs-fetch)\n![](https://img.shields.io/npm/v/alpinejs-fetch)\n![](https://img.shields.io/npm/dt/alpinejs-fetch)\n![](https://img.shields.io/github/license/markmead/alpinejs-fetch)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-fetch/lists"}