Skip to content
This repository

. . .

Deprecation Note

This documentation is for release 0.9.0 (from 03/2012), which is built against Scala 2.9.1 and Akka 1.3.1 (see Requirements for more information). Most likely, this is not the place you want to look for information. Please turn to the main spray site at http://spray.io for more information about other available versions.

. . .

The spray source code repository contains a folder called spray-examples that contains a number of example projects demonstrating different aspects of spray.

(NOTE: This page targets an outdated version of spray. For the most recent documentation please visit http://spray.io/)

Simple Example

This example defines a very simple web application built with 2 HttpServices. This is its service definition.

You can try it out like this:

  1. Clone the spray source code repository
  2. cd into the base directory
  3. Run sbt "project spray-example-simple" shell to start sbt
  4. Run container:start to start the example app
  5. Point your browser to http://localhost:8080

Calculator Example

This example defines a simple REST service offering basic calculations. This is its service definition.

  1. Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-calculator"
  2. In another terminal run curl http://localhost:8080/add/10.5/31.5 or point your browser to the respective URL

Markdown-Server Example

This example shows how spray can be used to serve up static files from JAR resources.

Its MarkdownService trait defines a custom media type for markdown files that are being served under the "/doc" path from a JAR resource "directory". The example uses a simple response transformation to convert content with the "text/x-markdown" type to HTML using pegdown.

You can try it out like this:

  1. Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-markdownserver"
  2. Point your browser to http://localhost:8080/doc

Stopwatch Example

The Stopwatch example is a somewhat more elaborate example demonstrating, among other things, custom marshallers and method tunneling via query parameters. This is its main service definition.

You can try it out like this:

  1. Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-stopwatch"
  2. Point your browser to http://localhost:8080/

spray-can Example

The "spray-example-spray-can" project demonstrates how spray-server can be run on top of the spray-can HttpServer, without any servlet container. You can run it with sbt "project spray-example-spray-can" run. This is its Boot object.

If you have a particularly clever example for a spray-server service we'd be more than happy to include it (as is the case with all contributions).

Something went wrong with that request. Please try again.