5 ms·
This is great! I had to create an xhr-fetch-proxy to use fetch and htmx. This change should open up a lot of fun possibilities. https://github.com/logankeenan/
by logankeenan 11mo ago
This is great! I had to create an xhr-fetch-proxy to use fetch and htmx. This change should open up a lot of fun possibilities.
https://github.com/logankeenan/xhr-fetch-proxy https://github.com/logankeenan/xhr-fetch-proxy
- recursivedoubts 11mo agoin 4.0 the request cycle is totally open: you can replace the fetch() implementation on a per-request basis learned that trick from fixi.js
- logankeenan 11mo agoYep, it's super nice. The Service Workers API also makes this really easy too. I experimented with compiling a Rust Axum server to WASM and then ran it in my service worker. Also, thanks for incorporating fetch into htmx! I thought I'd include an example of replacing fetch for anyone that come across this. const originalFetch = window.fetch; window.fetch = function(url, options) { if (url.includes('/api/user')) { const mockUser = {id: 1, name: 'John Doe', email: 'john@example.com'}; return Promise.resolve(new Response(JSON.stringify(mockUser))); } return originalFetch(url, options); }; https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/fetch_event https://developer.mozilla.org/en-US/docs/Web/API/ServiceWork...
- recursivedoubts 11mo agoin htmx 4 you are able to swap it on a per-trigger basis, so need to muck w/the global fetch function: <button hx-get="/foo" hx-on:htmx:config:request="ctx.fetch = myCustomFetch"> Do It </button>
- logankeenan 11mo agoOh that’ll be much nicer. Would myCustomFetch then need to return a Response? https://developer.mozilla.org/en-US/docs/Web/API/Response https://developer.mozilla.org/en-US/docs/Web/API/Response