This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 566
Home
sirthias edited this page Apr 14, 2011
·
44 revisions
spray is a lightweight Scala framework for building RESTful web services on top of Akka actors and Akka Mist. It sports the following main features:
- Completely asynchronous, non-blocking, actor-based request processing for efficiently handling very high numbers of concurrent connections
- Powerful, flexible and extensible internal Scala DSL for declaratively defining your web service behavior
- Immutable model of the HTTP protocol, decoupled from the underlying servlet container
- Full testability of your REST services, without the need to fire up containers or actors
import cc.spray._
trait HelloServiceBuilder extends ServiceBuilder {
val helloService = {
path("hello") {
get { _.complete(<h1>Say hello to Spray</h1>) }
}
}
}
Please use the http://groups.google.com/group/spray-user/ mailing list!
This is what a somewhat more complex spray service might look like:
val service = {
path("orders") {
get {
// marshal custom object with in-scope marshaller
_.complete(getOrdersFromDB())
} ~
post {
// unmarshal with in-scope unmarshaller
contentAs[Order] { order =>
// transfer to newly spawned actor
detached { ctx =>
// ... write order to DB
ctx.complete("Order received")
}
}
}
} ~
// use regex to extract URI element
pathPrefix("order" / "\\\\d+".r) { orderId =>
path("") {
// method tunneling via query param
(put | parameter('method ! "put")) {
contentAs[Order] { order => ctx =>
// transfer request handling to custom actor
myDbActor ! Update(order, ctx)
}
} ~
get {
// use in-scope marshaller to create completer function
produces[Order] { complete =>
_ => complete(getOrderFromDB(orderId))
}
}
} ~
path("items") {
parameters('size, 'color ?, 'dangerous ? "no") {
(size, color, dangerous) =>
// ... route using required and optional query parameters
}
}
} ~
path("documentation") {
// cache responses to GET requests
cached {
// serve up static content from a JAR resource
getFromResourceDirectory("docs")
}
}
}
spray is released under the Apache License 2.0.
Portions of the immutable HTTP model are
copyright (C) 2010-2011 by the BlueEyes Web Framework Team
- Home
- Requirements
- ... 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