Posts

Showing posts with the label JSON

HTMX experiments: re-use URL for multiple hx-get attributes

I was able to successfully create a codepen that demonstrated how to use various triggers to make HTMX start an API call. One issue I had with that experiment was that I had to write the URL of the API multiple times for each example. Second task: find a way to declare only one URL and re-use that URL in multiple hx-get instances. Note that my main goal here is to understand how to effectively use HTMX for client-server communication. I start my experiment by reading the answer found here: How to configure base url for all requests using HTMX About htmx:configRequest I learned that HTMX has a htmx:configRequest event that can be used to modify the URL used in the request. Since this event fires up before HTMX makes the API call, it is still possible to modify the URL via the event.detail.path parameter. However, using this feature requires adding custom JavaScript code which waits for the event to fire. For reference, see the HTML code in the codepen instance below:...

HTMX experiments: triggers

I've been hearing a lot about HTMX so I decided to look into it. I also plan to create a new web app and felt that HTMX would be a great fit. However, I am wholly unfamiliar with the framework, so I decided to document my journey via these posts. First experiment: use HTMX to communicate with a public API server that returns a text string . As per my research, the workflow runs like this: Trigger HTMX to call the API server. → API server returns a response to HTMX. → HTMX parses the response received. Note that my main goal here is to understand how to effectively use HTMX for client-server communication. I start my journey by reading the documentation found here: https://htmx.org/attributes/hx-trigger/ Triggers I learned that triggers are events or actions that will make HTMX send an API call. After a few attempts, I created the codepen below which provides quick examples of triggers supported by HTMX: ...