Alpine: [request] Fetch wrapper

Created on 1 Feb 2020  路  5Comments  路  Source: alpinejs/alpine

I think this might be be usefull to retrieve dynamic data for dropdowns

<div x-fetch:items="{url: 'api.address.url'}">
    <template x-for="item in items" :key="item">
        <div x-text="item"></div>
    </template>
</div>

Most helpful comment

I was thinking of attempting this if/when there was a plugin API for Alpine. Something along the lines of Intercoolerjs but smaller and integrated into Alpine. I'm not sure if this fits into the Alpine core or if it would be better developed as an add-on/plugin.

All 5 comments

This is a really good idea imho, I would welcome this wrapper even though writing fetch functions isn't that hard.

I was thinking of attempting this if/when there was a plugin API for Alpine. Something along the lines of Intercoolerjs but smaller and integrated into Alpine. I'm not sure if this fits into the Alpine core or if it would be better developed as an add-on/plugin.

Yeah this would be great to have natively or through the custom directive feature under discussion. intercooler style behavior would be useful.

Maybe an x-async or x-await similar to svelte, that handles promises to conditionally render pending / resolved / rejected states.

Edit: This would face the same issue as x-else does though.

Eventually, we will likely add a custom directive system so you could define things like this yourself and publish them as third party packages.

But I don't envision adding something like this as a first-class offering.

Closing for now.

Was this page helpful?
0 / 5 - 0 ratings