package rest
- Alphabetic
- Public
- All
Type Members
- trait Continuation extends AnyRef
- case class ContinuationKey (path: ParsePath, reqType: RequestType) extends Product with Serializable
-
trait
JsonXmlAble
extends AnyRef
A trait that can be mixed into an class (probably a case class) so that the class can be converted automatically into JSON or XML
-
sealed
trait
JsonXmlSelect
extends AnyRef
This trait is part of the ADT that allows the choice between
-
final
class
ListServeMagic
extends AnyRef
Do some magic to prefix path patterns with a single List
-
trait
RestHelper
extends DispatchPF
Mix this trait into a class to provide a list of REST helper methods
-
trait
XMLApiHelper
extends AnyRef
Mix this trait into your REST service provider to convert between different response types and a LiftResponse.
Mix this trait into your REST service provider to convert between different response types and a LiftResponse. You need to define the createTag method to provide a root element for your API. You may optionally override the successAttrName, operationAttrName, and/or msgAttrName defs to control the attributes that will be applied to your root element based on the return from your API.
For example, the following code implements a simple API that takes a comma- separated string of integers and reduces them with various operations.
object CalculatorApi extends XmlApiHelper { // Define our root tag def createTag(contents : NodeSeq) : Elem = <api>{contents}</api> // The LiftResponses here will be converted to Box[LiftResponse] // via the putResponseInBox implicit conversion def calculator : LiftRules.DispatchPF = { case r @ Req(List("api","sum"), _, GetRequest) => () => doSum(r) case r @ Req(List("api","product"), _, GetRequest) => () => doProduct(r) case r @ Req(List("api","max"), _, GetRequest) => () => doMax(r) case r @ Req(List("api","min"), _, GetRequest) => () => doMin(r) case Req("api" :: _, _, _) => () => BadResponse() } // Define a common handler def reduceOp (operation : (Int,Int) => Int)(r : Req) : Box[Elem] = tryo { (r.param("args").map { args => <result>{args.split(",").map(_.toInt).reduceLeft(operation)}</result> }) ?~ "Missing args" } match { case Full(x) => x case f : Failure => f case Empty => Empty } // Using a return type of LiftResponse causes the canNodeToResponse // implicit to be invoked def doSum (r : Req) : LiftResponse = reduceOp(_ + _)(r) def doProduct (r : Req) : LiftResponse = reduceOp(_ * _)(r) def doMax (r : Req) : LiftResponse = reduceOp(_ max _)(r) def doMin (r : Req) : LiftResponse = reduceOp(_ min _)(r) }
With this API, the URL
http://foo.com/api/sum?args=1,2,3,4,5
would return<api operation="sum" success="true"><result>15</result></api>
http://foo.com/api/sum?args=1,2,3,4,5 return
<api operation="sum" success="true"><result>15</result></api>
Value Members
- object ContinuationsStore extends SessionVar[HashMap[ContinuationKey, Continuation]]
-
object
JsonSelect
extends JsonXmlSelect with Product with Serializable
The Type for JSON
-
object
RestContinuation
Provides a generic way of sending asynchronous response to HTTP clients.
Provides a generic way of sending asynchronous response to HTTP clients. If the underlying web container does not support continuations the asynchronous nature is achieved using locks.
-
object
XmlSelect
extends JsonXmlSelect with Product with Serializable
The type for XML