-
Notifications
You must be signed in to change notification settings - Fork 0
Example Projects
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/)
This example defines a very simple web application built with 2 HttpServices. This is its service definition.
You can try it out like this:
- Clone the spray source code repository
-
cdinto the base directory - Run
sbt "project spray-example-simple" shellto start sbt - Run
container:startto start the example app - Point your browser to
http://localhost:8080
This example defines a simple REST service offering basic calculations. This is its service definition.
- Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-calculator"
- In another terminal run
curl http://localhost:8080/add/10.5/31.5or point your browser to the respective URL
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:
- Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-markdownserver"
- Point your browser to
http://localhost:8080/doc
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:
- Follow steps 1 through 4 of the instruction for the "Simple Example" above but change "spray-example-simple" to "spray-example-stopwatch"
- Point your browser to
http://localhost:8080/
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).
- Home
- Requirements
- spray-server
- ... Getting Started
- ... Key Concepts
- ...... Request Lifecycle
- ...... Routes
- ...... Directives
- ...... Composing Directives
- ...... Rejections
- ...... Marshalling and Unmarshalling
- ... Predefined Directives
- ...... Method Filters
- ...... Path Filters
- ...... Parameter Filters
- ...... Form-Field Filters
- ...... Marshalling/Unmarshalling
- ...... Caching
- ...... Detach
- ...... Encoding/Decoding
- ...... Authentication/Authorization
- ...... File and Resource Directives
- ...... Misc Directives
- ... Advanced Topics
- ...... Case Class Extraction
- ...... Custom Directives
- ...... Custom Media Types
- ...... Custom Error Responses
- ... Configuration
- ... Testing
- ... Example Projects
- spray-client
- Patch Policy
- Credits
- Sponsors