1. Vetle Leinonen-Roeim
  2. minihttpserver


Build Status


A minimal library for embedding an HTTP server, written in Scala. Mostly copied from this answer by the user Tommy at StackOverflow. Note that this isn't an implementation of an HTTP server, it just uses the one available in the JDK.

This project is cc-by-sa licensed.

How to use

Assuming you use SBT, add the following resolver and library dependencies:

resolvers += "Roeim.net repository" at "http://roeim.net/maven"

libraryDependencies += "net.roeim.minihttpserver" %% "minihttpserver" % "1.0"

Next, extend MiniHttpServer and define routes, as shown here in an example taken from the test code:

class TestServer extends MiniHttpServer {
  get("/") { exchange => 
    exchange.getResponseHeaders().add("Content-type", "text/html")
    "It works!"

  get("/foo") { exchange =>
    exchange.getResponseHeaders().add("Content-type", "text/plain")
    "And here's foo."

After this, it needs to be started, as follows:

val server = new TestServer
// ...
// and when you're done: