{"id":16788736,"url":"https://github.com/markmead/alpinejs-axios","last_synced_at":"2025-04-10T23:24:59.772Z","repository":{"id":198036124,"uuid":"699906168","full_name":"markmead/alpinejs-axios","owner":"markmead","description":"Alpine JS magic methods wrapper for Axios API methods 📨","archived":false,"fork":false,"pushed_at":"2025-03-07T08:13:45.000Z","size":149,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T20:12:30.034Z","etag":null,"topics":["alpinejs","alpinejs-data","alpinejs-plugin","axios","axios-plugin"],"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":"2023-10-03T15:12:30.000Z","updated_at":"2025-03-18T17:44:04.000Z","dependencies_parsed_at":"2025-02-18T05:31:32.688Z","dependency_job_id":"af9f8935-e306-4776-900e-a3a6093210ef","html_url":"https://github.com/markmead/alpinejs-axios","commit_stats":null,"previous_names":["markmead/alpinejs-axios"],"tags_count":0,"template":false,"template_full_name":"markmead/alpinejs-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-axios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-axios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-axios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmead%2Falpinejs-axios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmead","download_url":"https://codeload.github.com/markmead/alpinejs-axios/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313613,"owners_count":21082885,"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-data","alpinejs-plugin","axios","axios-plugin"],"created_at":"2024-10-13T08:24:33.202Z","updated_at":"2025-04-10T23:24:59.752Z","avatar_url":"https://github.com/markmead.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpine JS Axios\n\nAlpine JS magic methods wrapper for Axios API methods 📨\n\n## Install\n\n### With a CDN\n\n```html\n\u003cscript\n  defer\n  src=\"https://unpkg.com/alpinejs-axios@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-axios\n\nnpm install -D alpinejs-axios\n```\n\n```js\nimport Alpine from 'alpinejs'\nimport api from 'alpinejs-axios'\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```js\nconst { data } = axios.get('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-axios)\n![](https://img.shields.io/npm/v/alpinejs-axios)\n![](https://img.shields.io/npm/dt/alpinejs-axios)\n![](https://img.shields.io/github/license/markmead/alpinejs-axios)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-axios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmead%2Falpinejs-axios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmead%2Falpinejs-axios/lists"}