Skip to content

ijuma/scala-embedded-jetty

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple scala shim for configuring and running embedded jetty

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 98.0%
  • Shell 1.5%
  • HTML 0.5%