| 1 | --- |
| 2 | title: "htmx:before:request" |
| 3 | description: "Immediately before fetch is called" |
| 4 | --- |
| 5 | |
| 6 | The `htmx:before:request` event fires immediately before the `fetch()` call is made. |
| 7 | |
| 8 | ## When It Fires |
| 9 | |
| 10 | Right before the network request is sent, after all configuration and validation. |
| 11 | |
| 12 | ## Event Detail |
| 13 | |
| 14 | - `ctx` - Request context object with final request configuration |
| 15 | |
| 16 | ## Example |
| 17 | |
| 18 | ```javascript |
| 19 | htmx.on('htmx:before:request', (evt) => { |
| 20 | console.log('Sending request to:', evt.detail.ctx.request.action); |
| 21 | // Show loading indicator |
| 22 | }); |
| 23 | ``` |
| 24 | |
| 25 | Cancel this event to prevent the request from being sent. |