hx-pod

The htmx request header that tells you
EXACTLY where the user is making the request from
The full url string with all ids and params

What is hx-pod?

Join me while I learn HTMX and talk at you about it
Twitter: @htmxlabs

Lazarus:

So we're almost done with the request headers, and the next one on here is the h x current URL. So this just contains it's the header that's sent along with every single HTML request, and it just contains the current URL of the request. And this is something that, you know, your browser sort of already sends something that is the URL, of the request, which is the referrer. Referrer. But that's actually a little different.

Lazarus:

And not only is it is it different, and I'll get to that in a minute, but also the htmx version gives you the full URL that's up in your browser. So the referrer just is kind of the primary URL. It's not going to include if you, like, clicked on an ID and so there's a little pound hashtag ID thing, in the URL currently up at the bar. Your referrer is not gonna have that. It's also, you know, might not have the other parameters sent, and it's just it's it's a different thing.

Lazarus:

So part of, so the h tmx version basically is is more complete first of all, it's part of this sort of history management browser request headers so that you can kind of, you know, have a little control or knowledge at least about what's happening with the browser. So why would you need this? The main thing is, like, I'll just sort of repeat, you rarely need any of the request headers, in my opinion. They just generally work in the background. They're sent, but you could have a special case where you just need to know that type of information, like, where were they when they clicked this.

Lazarus:

Actually could be very useful information. Let's say you wanted to know what page number of a list they were on. That might be one example. There are other ways to do this kind of stuff and, you know, most of the time your logic is not going to involve this, but you could parse out the current URL and find out. That could just be part of your application is knowing what the current URL is and you wanna do something with that knowledge, good.

Lazarus:

Or, you know, it doesn't have to be just a page number just any query parameter in particular of the current page that the user is on. And this is so remember this is not the URL sent with the request. Like, if you send something to HTMLX and you have in the hx get equals that URL, it's not that URL. This is the URL of the browser that the user is on currently, the full URL, that just gets sent along with the htmx request. It's the page the request was sent from.

Lazarus:

It's not the thing in the hx get, that's an important distinction. So you might have a small snippet being loaded, but it's being loaded into a page that has some parameter on it, details equals true or something, so you can check that if you want to. And maybe that's a way for you to know how to handle the snippet your servit sends back your server sends back. So that's not what I would normally do. That's kind of just a made up, you know, like again, this is just, you know, some sort of trying to imagine what you might want to use this for, what you could use it for.

Lazarus:

But these tools, these request headers, are all about empowering you to do the things you want to do, even if sometimes maybe they're the dumb way, maybe it's not a great way to do something, maybe it's not the ideal way. If that's what you want to do, you know, you know your needs best, your needs are your own. In this case, you can just always get the current URL that the user is seeing. So when they sending HTML requests, that is information that you can decide what to do with. That's kind of a luxury that you don't always have on the back end of the server side of knowing what the exact URL a request is coming from.

Lazarus:

Including all the details and the ID and the parameters and everything like that. So if that's useful to you then, you know, the browser, the request header, the h tmx request header to use is h x current URL.