Liking cljdoc? Tell your friends :D

ring-http-exchange

Clojure ring adapter for com.sun.net.httpserver.HttpServer which is included in the JDK.

The main motivation for this is to support starting a small HTTP server inside an application which itself isn't necessary primarily a web app, while avoiding adding any new major dependencies on the classpath.

Clojars Project

Installation

Add ring-http-exchange to dependency list

[org.clojars.jj/ring-http-exchange "1.2.1"]

robaho httpserver

For better performance, robaho httpserver can be added to the dependency list. It is a drop-in replacement for a com.sun.net.httpserver

[io.github.robaho/httpserver "1.0.27"]

Usage

(:require [ring-http-exchange.core :as server])
(server/run-http-server
  (fn [_]
    {:status 200
     :headers {"Content-Type" "text/html; charset=utf-8"}
     :body "hello world"})
  {:port 8080
   :ssl-context (ssl/keystore->ssl-context 
                                      (io/resource "keystore.jks") "keystore-password"
                                      (io/resource "truststore.jks") "truststore-password")
   :executor (Executors/newVirtualThreadPerTaskExecutor)})

Supported response body types

Response Body Type
java.lang.String
java.io.InputStream
java.io.File
byte[]
ring.core.protocols/StreamableResponseBody

Server configuration

PropertyDescriptionDefault value
hostHost name0.0.0.0
portApplication port8080
executorExecutor to be usedCachedThreadPool
ssl-contextSsl context to be used in https configuratornil

Limitations

  • Transfer-Encoding header will be set to chunked, if it is not possible to get length of the body.

License

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Can you improve this documentation? These fine people already did:
Jj, Håkan Råberg & jj
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close