Skip to content

This is a simple example of using WebSockets with HTMX

Notifications You must be signed in to change notification settings

chuhlomin/htmx-websockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmx-websockets

This is a simple example of using WebSockets with HTMX.
It uses the htmx WebSockets extension to connect to a websocket server and echo messages back to the client.

Server

The server is written in Go and uses the gorilla/websocket package to handle WebSockets.

Routes:

  • / - serves the index page
  • /events - handles websocket connections
  • /webhook - handles POST requests and broadcasts the body to all connected clients

Server keeps last 10 messages in memory and broadcasts them to new clients.

Running the server

go run .

Then open http://localhost:8080 in your browser.

Try opening multiple browsers and see list of connected clients update.

Send a message to all connected clients:

curl -X POST -d '{"message": "Hello, world!"}' http://localhost:8080/webhook

About

This is a simple example of using WebSockets with HTMX

Topics

Resources

Stars

Watchers

Forks

Languages