Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 2.02 KB

README.md

File metadata and controls

62 lines (42 loc) · 2.02 KB

scala-embedded-jetty Build Status Download

A scala shim for running embedded jetty (http only currently)

Requirements

Usage

Add the following lines to your build.sbt

resolvers += "Tim Tennant's repo" at "http://dl.bintray.com/timt/repo/"

val jettyVersion="9.2.9.v20150224"

libraryDependencies ++= Seq(
  "io.shaka"            %%  "scala-embedded-jetty"  % "10"
  "org.eclipse.jetty"   %   "jetty-webapp"          % jettyVersion,
  "org.eclipse.jetty"   %   "jetty-plus"            % jettyVersion,
  "org.eclipse.jetty"   %   "jetty-servlets"        % jettyVersion,

Starting a server

import io.shaka.jetty.EmbeddedJetty
val embeddedJetty = jetty.start()  //Start on some free port
...
val embeddedJetty = jetty(1234).start() //Start on port 1234

Customise configuration

import io.shaka.jetty.JettyConfiguration
val jettyConfiguration = JettyConfiguration(port = 1234, webappDirectory = "src/resource/webapp")
val embeddedJetty = jetty(jettyConfiguration).start()

Stopping the server

embeddedJetty.stop()

Providing a custom context handler

io.shaka.http.Response.respond
io.shaka.http.Request
jetty
    .addHandler("/my-context", (request: Request) => {
      respond("<h1>Hello World</h1>".getBytes)
    })
    .start()

For more examples see

Code license

Apache License 2.0