An open API service indexing awesome lists of open source software.

https://github.com/markmead/alpinejs-axios

Alpine JS magic methods wrapper for Axios API methods 📨
https://github.com/markmead/alpinejs-axios

alpinejs alpinejs-data alpinejs-plugin axios axios-plugin

Last synced: about 1 month ago
JSON representation

Alpine JS magic methods wrapper for Axios API methods 📨

Awesome Lists containing this project

README

        

# Alpine JS Axios

Alpine JS magic methods wrapper for Axios API methods 📨

## Install

### With a CDN

```html

```

### With a Package Manager

```shell
yarn add -D alpinejs-axios

npm install -D alpinejs-axios
```

```js
import Alpine from 'alpinejs'
import api from 'alpinejs-axios'

Alpine.plugin(api)

Alpine.start()
```

## Example

### GET

```html



Get




```

### POST

```html



Create




```

### PUT/PATCH

```html




Update




```

### DELETE

```html



Delete




```

## Filtering the Response

A lot of the times you only need a property from the response object, this is
usually `data`. You'll see/write stuff like this:

```js
const { data } = axios.get('https://dummyjson.com/products/1')
```

With this package you can do that by adding `[data]` to the end of the URL.

```html




Get




Get




```

This works for all the requests and isn't limited to the `data` property.
Anything that is part of the response object can be used to filter the response.
For example, `[status]`.

_Heads up! Syntax is important, the filter property key must be place in square
brackets `[x]`._

### Nested Filters

Sometimes you don't want the whole object back, in this example `data` returns a
lot of information but we only want `title` and `price` back. Here's how you can
do that.

```html


Get

```

This will return with the first key, in this case `data` omitted.

```json
{
"title": "iPhone 9",
"price": 549
}
```

_Note! You can still pass other filters in when using nested filters, something
like `[data.title, status]` will work fine!_

## Stats

![](https://img.shields.io/bundlephobia/min/alpinejs-axios)
![](https://img.shields.io/npm/v/alpinejs-axios)
![](https://img.shields.io/npm/dt/alpinejs-axios)
![](https://img.shields.io/github/license/markmead/alpinejs-axios)