{"id":7203,"date":"2025-09-15T10:30:27","date_gmt":"2025-09-15T14:30:27","guid":{"rendered":"https:\/\/www.simplethread.com\/?p=7203"},"modified":"2025-09-15T13:12:06","modified_gmt":"2025-09-15T17:12:06","slug":"interception","status":"publish","type":"post","link":"https:\/\/www.simplethread.com\/interception\/","title":{"rendered":"Interception!"},"content":{"rendered":"<p>It\u2019s American football season again and, as many fans will attest, there are few things more exciting than intercepting a ball thrown by the opposing team\u2019s quarterback \u2013 it can truly be a game-changer! Similarly, utilizing JS (JavaScript) HTMX extensions to intercept responses in your web application can yield equally exciting results. By providing new inflection points in the code (i.e. capturing responses before a specific target is updated), developers can inject a variety of useful functionality that would otherwise be overly complex or convoluted to implement effectively. In this post, I will present 3 distinct examples of how responses can be intercepted and leveraged to extend HTMX\/Flask interactions beyond simple attribute-based GET and POST requests and responses.<\/p>\n<h2>Example 1 \u2013 Error Handling<\/h2>\n<p>Sometimes, in football, plays break down, and it\u2019s up to the players to handle that breakdown elegantly and intelligently. For example, a quarterback might throw the ball out of bounds if no one is available for a pass to avoid taking a sack. Likewise, in a web application, when something breaks down on the server or in the code during a request, it will likely elicit an error in the response that should be gracefully handled. To do this, we can simply add a JS listener utilizing the <strong>htmx:afterRequest<\/strong> event. <a href=\"https:\/\/htmx.org\/events\/\" target=\"_blank\" rel=\"noopener\">Per the documentation<\/a>:<\/p>\n<p><em>This event is triggered after an AJAX request has finished, either in the case of a successful request (although one that may have returned a remote error code such as a 404) or in a network error situation<\/em><\/p>\n<p>Combined with the <strong>failed<\/strong> event detail, we can determine whether the response was successful or not. If not, we can implement code to handle the failure accordingly. In the basic example below, an alert is displayed if a failure occurs; however, this could easily be replaced with more robust error handling:<\/p>\n<pre><code class=\"language-js\">\r\n1. document.addEventListener('htmx:afterRequest', event =&gt; {\r\n2.     if(event.detail.failed){\r\n3.         alert(\"Error - Please contact an administrator\")\r\n4.     }\r\n5. })\r\n<\/code><\/pre>\n<h2>Example 2 \u2013 HTMX Request Chaining<\/h2>\n<p>Sometimes in football, a more complex offensive play can have several \u201csteps\u201d as the team attempts to move the ball forward. An example of this would be something like a \u201creverse\u201d where the quarterback hands the ball off to a player running in one direction, who then, in turn, hands the ball off to another player running in the opposite direction. Similarly, there are situations in which a developer may need to \u201cchain\u201d requests, where upon reception of a response from one request, another request is subsequently issued (i.e. the application flow is handed off between distinct endpoints). An example we recently faced was the need to utilize an existing Flask route without modifying the endpoint or its response but ultimately pass back a custom response targeting parts of the UI (User Interface) for refresh. After making the initial HTMX request, we could intercept the response from that first endpoint and then kick off a subsequent ajax request to a secondary endpoint that would target a refresh of the necessary UI components. Below is a generic example illustrating how this can be accomplished using HTMX custom extensions.<\/p>\n<h3>Part 1 (Initial Request)<\/h3>\n<p>In the front-end code, we use standard HTMX attributes to post a request to the initial endpoint:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-7214\" src=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/click-me-1024x229.jpg\" alt=\"\" width=\"640\" height=\"143\" srcset=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/click-me-1024x229.jpg 1024w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/click-me-300x67.jpg 300w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/click-me-768x172.jpg 768w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/click-me.jpg 1180w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>The first thing to note is that the hx-swap attribute is set to \u2018none\u2019. This ensures that the response content is not appended to the DOM (Document Object Model). Secondly, we have included the hx-ext attribute to name our custom HTMX extension. This is used to identify the extension definition in our JS code.<\/p>\n<h3>Part 2 (Interception and Secondary Request)<\/h3>\n<p>Below is the JS definition of the HTMX extension that we created. Again, we were able to leverage an HTMX event to intercept the response from the first endpoint, parse it and then execute another HTMX request to the secondary endpoint. For this particular piece of code, we used the <strong>htmx:afterOnLoad<\/strong> event to intercept the response. <a href=\"https:\/\/htmx.org\/events\/\" target=\"_blank\" rel=\"noopener\">Per the documentation<\/a>:<\/p>\n<p><em>This event is triggered after an AJAX onload has finished. Note that this does not mean that the content has been swapped or settled yet, only that the request has finished.<\/em><\/p>\n<p>Since we don&#8217;t need or want to update the DOM with the response from the first request, we can intercept it using this event type.<\/p>\n<p>In the extension definition example below, we have an <strong>onEvent<\/strong> listener listening for the <strong>htmx:afterOnLoad<\/strong> event. When that is returned successfully, we issue an HTMX ajax call to the second endpoint targeting the UI components to be refreshed (in this case it\u2019s the #search-results element) effectively chaining the two requests back-to-back.<\/p>\n<pre><code class=\"language-js\">1. htmx.defineExtension('htmx-project-reload', {\r\n 2.     onEvent: function (name, evt) {\r\n 3.         if(name == 'htmx:afterOnLoad'){\r\n 4.             const status = evt.detail.xhr.status;\r\n 5.             if(status == 200){\r\n 6.                 htmx.ajax('POST', '\/second_endpoint',\r\n 7.                     {target: '#search-results', indicator: '#loading-message'}\r\n 8.                 )\r\n 9.             }\r\n10.         }\r\n11.         return true;\r\n12.     }\r\n13. })\r\n<\/code><\/pre>\n<h2>Example 3 \u2013 File Download<\/h2>\n<p>When a football coach finds that a particular type of play isn\u2019t working or isn\u2019t appropriate for the current down and distance, they might try using a different type of play. For example, if running the ball isn\u2019t working well, they may choose to try and pass the ball through the air instead, particularly if they have a large distance still to cover since it\u2019s better suited for that situation. In the case of providing file downloads to users, there are, of course, different ways to accomplish this. One of the easiest is to simply provide a link to the file location using basic HTML (Flask example below):<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7213\" src=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/download-1024x95.jpg\" alt=\"\" width=\"640\" height=\"59\" srcset=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/download-1024x95.jpg 1024w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/download-300x28.jpg 300w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/download-768x71.jpg 768w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/download.jpg 1418w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>In many cases, this implementation may be totally adequate. However, what if you want to display an indicator while the report is generating or provide improved error handling if report generation fails? In this case, you may want to switch up the implementation and leverage HTMX attributes and events to handle the file download since it is better suited for those types of situations. The example below is based off a great post by <a href=\"https:\/\/medium.com\/@martin.mohnhaupt\/an-htmx-file-download-extension-cccfaba5e2e2\" target=\"_blank\" rel=\"noopener\">Martin Mohnhaupt over on Medium.com<\/a> where he does just that, albeit with a few of our own minor tweaks.<\/p>\n<h3>Part 1 (Initial Request)<\/h3>\n<p>First, the button is created on the front-end using attributes to define the HTMX post configuration:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-7212\" src=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/button-1024x342.jpg\" alt=\"\" width=\"640\" height=\"214\" srcset=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/button-1024x342.jpg 1024w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/button-300x100.jpg 300w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/button-768x256.jpg 768w, https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/button.jpg 1156w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Like our last example, we have set the <strong>hx-swap<\/strong> attribute to \u201cnone\u201d so that the response does not impact the DOM in any way. The <strong>hx-ext<\/strong> is also set to identify the name of the extension in our JS definition code and lastly, we have added the <strong>hx-indicator<\/strong> to identify the \u201cloading\u201d element in our UI that will be displayed as the report generates.<\/p>\n<p>Also of note, the \u201c\/export\u201d endpoint generates the report content and then sends the bytes using an in-memory bytes buffer to the client as part of the response:<\/p>\n<pre><code class=\"language-js\">1. with open(\"report.csv\", \"rb\") as file:\r\n2.     file_contents = file.read()\r\n3.     return send_file(BytesIO(file_contents), as_attachment=True, download_name=\"report.csv\")\r\n<\/code><\/pre>\n<h3>Part 2 (Interception and file download)<\/h3>\n<p>Once again, when the response is sent, we intercept it using the <strong>htmx:afterOnLoad<\/strong> event in our JS HTMX extension definition. Assuming that the response is successful, the headers and content are parsed to retrieve the necessary data for download including the filename and MIME type. Next, a hidden link element is created and given attributes populated with the parsed information. To ensure that there are no issues with the href content, we encode the response payload binary data to base64 using the built in JS btoa function. Lastly, the newly created link element is clicked programmatically, prompting the download in the client and then removed from the DOM since it is no longer needed for this specific download.<\/p>\n<pre><code class=\"language-js\">1. htmx.defineExtension('htmx-download', {\r\n 2.     onEvent: function (name, evt) {\r\n 3.         if(name == 'htmx:afterOnLoad'){\r\n 4.             const status = evt.detail.xhr.status;\r\n 5.             if(status == 200){\r\n 6.                 const response = evt.detail.xhr.response;\r\n 7.                 const headers = get_headers(evt.detail.xhr);\r\n 8.                 const filename = headers['content-disposition'].split('=')[1];\r\n 9.                 const mimetype = headers['content-type'];\r\n10.  \r\n11.                 const link = document.createElement(\"a\");\r\n12.                 link.style.display = \"none\";\r\n13.                 link.href = `data:${mimetype};base64,${btoa(response)}`;\r\n14.                 link.download = filename;\r\n15.  \r\n16.                 document.body.appendChild(link);\r\n17.                 link.click();\r\n18.  \r\n19.                 setTimeout(()=&gt;{\r\n20.                     URL.revokeObjectURL(link.href);\r\n21.                     link.parentNode.removeChild(link);\r\n22.                 }, 100);\r\n23.             }\r\n24.         }\r\n25.         return true;\r\n26.     }\r\n27. })\r\n<\/code><\/pre>\n<p>The <strong>get_headers()<\/strong> function called in the above code parses the header contents into a JavaScript object and, per Martin Mohnhaupt\u2019s post, is inspired by the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/XMLHttpRequest\/getAllResponseHeaders\" target=\"_blank\" rel=\"noopener\">developer.mozilla.org code<\/a>.<\/p>\n<p>I have included his implementation below for convenience:<\/p>\n<pre><code class=\"language-js\">1. const get_headers = (xhr) =&gt; {\r\n 2.     \/\/ Get the raw header string\r\n 3.     const headers = xhr.getAllResponseHeaders();\r\n 4.     \/\/ Convert the header string into an arrayof individual headers\r\n 5.     const arr = headers.trim().split(\/[\\r\\n]+\/);\r\n 6.     \/\/ Create a map of header names to values\r\n 7.     const headerMap = {};\r\n 8.     arr.forEach((line) =&gt; {\r\n 9.         const parts = line.split(\": \");\r\n10.         const header = parts.shift();\r\n11.         const value = parts.join(\": \");\r\n12.         headerMap[header] = value;\r\n13.     });\r\n14.     return headerMap;\r\n15. }\r\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>As evidenced by these three very different examples, using HTMX events to intercept and parse responses can prove to be a powerful tool and provide for some exciting possibilities. From creating more robust error handling to extending built-in functionality, this concept can help make sure your next HTMX-enabled web application is a touchdown!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s American football season again and, as many fans will attest, there are few things more exciting than intercepting a ball thrown by the opposing team\u2019s quarterback \u2013 it can truly be a game-changer! Similarly, utilizing JS (JavaScript) HTMX extensions to intercept responses in your web application can yield equally exciting results. By providing new [&hellip;]<\/p>\n","protected":false},"author":78,"featured_media":7215,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[4],"tags":[5064,46],"class_list":["post-7203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-insights","tag-htmx","tag-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.3.1 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Interception! | Capturing and leveraging HTMX response events in unique ways - Simple Thread<\/title>\n<meta name=\"description\" content=\"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.simplethread.com\/interception\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Interception!\" \/>\n<meta property=\"og:description\" content=\"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.simplethread.com\/interception\/\" \/>\n<meta property=\"og:site_name\" content=\"Simple Thread\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Simple-Thread-164373486939165\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-15T14:30:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-15T17:12:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1644\" \/>\n\t<meta property=\"og:image:height\" content=\"1362\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ben Hood\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@simple_thread\" \/>\n<meta name=\"twitter:site\" content=\"@simple_thread\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ben Hood\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/\"},\"author\":{\"name\":\"Ben Hood\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/#\\\/schema\\\/person\\\/303df24c9fa898289653d73d92fd9fb4\"},\"headline\":\"Interception!\",\"datePublished\":\"2025-09-15T14:30:27+00:00\",\"dateModified\":\"2025-09-15T17:12:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/\"},\"wordCount\":1285,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg\",\"keywords\":[\"HTMX\",\"javascript\"],\"articleSection\":[\"Insights\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/\",\"url\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/\",\"name\":\"Interception! - Simple Thread\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg\",\"datePublished\":\"2025-09-15T14:30:27+00:00\",\"dateModified\":\"2025-09-15T17:12:06+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/#\\\/schema\\\/person\\\/303df24c9fa898289653d73d92fd9fb4\"},\"description\":\"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg\",\"contentUrl\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg\",\"width\":1644,\"height\":1362},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/interception\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.simplethread.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Interception!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/#website\",\"url\":\"https:\\\/\\\/www.simplethread.com\\\/\",\"name\":\"Simple Thread\",\"description\":\"Powering Energy Software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.simplethread.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/#\\\/schema\\\/person\\\/303df24c9fa898289653d73d92fd9fb4\",\"name\":\"Ben Hood\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg\",\"url\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.simplethread.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg\",\"caption\":\"Ben Hood\"},\"url\":\"https:\\\/\\\/www.simplethread.com\\\/author\\\/bhood\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Interception! | Capturing and leveraging HTMX response events in unique ways - Simple Thread","description":"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.simplethread.com\/interception\/","og_locale":"en_US","og_type":"article","og_title":"Interception!","og_description":"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.","og_url":"https:\/\/www.simplethread.com\/interception\/","og_site_name":"Simple Thread","article_publisher":"https:\/\/www.facebook.com\/Simple-Thread-164373486939165\/","article_published_time":"2025-09-15T14:30:27+00:00","article_modified_time":"2025-09-15T17:12:06+00:00","og_image":[{"width":1644,"height":1362,"url":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg","type":"image\/jpeg"}],"author":"Ben Hood","twitter_card":"summary_large_image","twitter_creator":"@simple_thread","twitter_site":"@simple_thread","twitter_misc":{"Written by":"Ben Hood","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.simplethread.com\/interception\/#article","isPartOf":{"@id":"https:\/\/www.simplethread.com\/interception\/"},"author":{"name":"Ben Hood","@id":"https:\/\/www.simplethread.com\/#\/schema\/person\/303df24c9fa898289653d73d92fd9fb4"},"headline":"Interception!","datePublished":"2025-09-15T14:30:27+00:00","dateModified":"2025-09-15T17:12:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.simplethread.com\/interception\/"},"wordCount":1285,"commentCount":0,"image":{"@id":"https:\/\/www.simplethread.com\/interception\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg","keywords":["HTMX","javascript"],"articleSection":["Insights"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.simplethread.com\/interception\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.simplethread.com\/interception\/","url":"https:\/\/www.simplethread.com\/interception\/","name":"Interception! - Simple Thread","isPartOf":{"@id":"https:\/\/www.simplethread.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.simplethread.com\/interception\/#primaryimage"},"image":{"@id":"https:\/\/www.simplethread.com\/interception\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg","datePublished":"2025-09-15T14:30:27+00:00","dateModified":"2025-09-15T17:12:06+00:00","author":{"@id":"https:\/\/www.simplethread.com\/#\/schema\/person\/303df24c9fa898289653d73d92fd9fb4"},"description":"Discover how to intercept HTMX responses in JavaScript to enhance Flask applications. Learn practical techniques for error handling, request chaining, and file downloads with clear code examples.","breadcrumb":{"@id":"https:\/\/www.simplethread.com\/interception\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.simplethread.com\/interception\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.simplethread.com\/interception\/#primaryimage","url":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg","contentUrl":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/09\/Capturing-and-leveraging-HTMX-Ben-Hood.jpg","width":1644,"height":1362},{"@type":"BreadcrumbList","@id":"https:\/\/www.simplethread.com\/interception\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.simplethread.com\/"},{"@type":"ListItem","position":2,"name":"Interception!"}]},{"@type":"WebSite","@id":"https:\/\/www.simplethread.com\/#website","url":"https:\/\/www.simplethread.com\/","name":"Simple Thread","description":"Powering Energy Software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.simplethread.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.simplethread.com\/#\/schema\/person\/303df24c9fa898289653d73d92fd9fb4","name":"Ben Hood","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/03\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg","url":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/03\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg","contentUrl":"https:\/\/www.simplethread.com\/wp-content\/uploads\/2025\/03\/79_Simple-Thread-Head-Shots-Ben-Hood-96x96.jpg","caption":"Ben Hood"},"url":"https:\/\/www.simplethread.com\/author\/bhood\/"}]}},"_links":{"self":[{"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/posts\/7203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/comments?post=7203"}],"version-history":[{"count":0,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/posts\/7203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/media\/7215"}],"wp:attachment":[{"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/media?parent=7203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/categories?post=7203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simplethread.com\/wp-json\/wp\/v2\/tags?post=7203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}