Skip to content
Mathias edited this page Jul 27, 2011 · 7 revisions

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

Calculator Example

This example defines a simple REST service offering basic calculations. 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 to start SBT in interactive mode
  4. run project spray-example-calculator
  5. run jetty-run to start the example app
  6. 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 examples 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 5 of the instruction for the "Calculator Example" above but change "spray-example-calculator" 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 5 of the instruction for the "Calculator Example" above but change "spray-example-calculator" to "spray-example-stopwatch"
  2. Point your browser to http://localhost:8080/

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).

Clone this wiki locally