Fetching data using Alpine is hard and non-intuitive #3068
hankhank10
started this conversation in
3. Feature Ideas
Replies: 2 comments 7 replies
-
Hi @hankhank10, I quickly tested your library. I have a few notions:
In any case, I think the |
Beta Was this translation helpful? Give feedback.
7 replies
-
I have opened a PR for this: #3086 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have developed a plugin for Alpine called alpine-fetch which makes it more intuitive to undertake HTTP requests using Alpine.
Would you consider adding functionality like this to the base alpine? If so, I would be very happy to open a pull request but wanted to check whether you see this as a value-added feature before doing that.
What is the issue?
HTMX is a popular library because it makes it really, really straightforward to send a request to and endpoint and populate a DOM element with the result. It is gaining a lot of traction from backend developers who want a straightforward way to add interactive elements without diving too much into Javascript, promises, etc.
I think Alpine is superior and more flexible than HTMX, but that adding functionality to streamline the process of making requests more straightforward.
Making requests with Alpine today
It's quite hard work and verbose:
(I'm aware this is a Javascript issue, not an Alpine issue)
Making requests with alpine-fetch
Much more intuitive as it abstracts away all of the promises and asyncs and other stuff that stump new JS devs.
Fetch some text and put it into a span:
or fetch some JSON and put a particular element into a span:
or load it into a x-data and use it wherever you want:
Links
More examples: https://hankhank10.github.io/alpine-fetch/
Source: https://github.com/hankhank10/alpine-fetch
Beta Was this translation helpful? Give feedback.
All reactions