Skip to content
/ talk Public

Netty — Clojure — HTTP — WebSockets: just enough of each.

License

Notifications You must be signed in to change notification settings

jdf-id-au/talk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Jeremy Field
Mar 2, 2025
a126d4d · Mar 2, 2025
Jun 13, 2022
Mar 10, 2024
Jul 25, 2023
Jun 21, 2022
Jun 21, 2022
Sep 21, 2021
Nov 4, 2021
Mar 2, 2025

Repository files navigation

jdf/talk

Netty HTTP + Websockets — Clojure core.async + spec

Just enough of each.

Exerts backpressure on both incoming and outgoing messages.

Outgoing messages are validated to spec; application/caller may choose to use provided specs for incoming messages. Routing and most HTTP protocol semantics are left to the application/caller; try jdf/foundation for this.

Streams uploads to disk above threshold size.

(Could use as sketch to update ring-adapter-netty.)

Usage

(require '[clojure.core.async :refer [<!! >!!]])
(require '[talk.api :as talk])
(require '[talk.ws :refer [->Text]])

(def server (talk/server! 8080 {:ws-path "/ws" :handler-timeout (* 10 1000)}))

; Use websocket client to visit ws://localhost:8080/ws
; Send a message

(<!! (:in server))
;=> talk.http.Connection record representing http connection
(<!! (:in server))
;=> talk.http.Connection record representing ws upgrade
(<!! (:in server))
;=> talk.ws.Text record representing message
(>!! (:out server) (->Text (:channel *1) "hello"))
; Message appears in ws client

; Use browser to visit http://localhost:8080/hello
; It will time out unless you're quick with the next steps!

(<!! (:in server))
;=> talk.http.Connection record representing http connection
(<!! (:in server))
;=> talk.http.Request record representing request

; Exercise for reader to set up proper async reply
; This one needs to be sent within timeout period!
(>!! (:out server)
  {:channel (:channel *1)
   :status 200
   :headers {:content-type "text/plain"}
   :content "hello"
  })

((:close server))

About

Netty — Clojure — HTTP — WebSockets: just enough of each.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published