Package

net.liftweb.http

rest

Permalink

package rest

Visibility
  1. Public
  2. All

Type Members

  1. trait Continuation extends AnyRef

    Permalink
  2. case class ContinuationKey(path: ParsePath, reqType: RequestType) extends Product with Serializable

    Permalink
  3. trait JsonXmlAble extends AnyRef

    Permalink

    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

  4. sealed trait JsonXmlSelect extends AnyRef

    Permalink

    This trait is part of the ADT that allows the choice between

  5. final class ListServeMagic extends AnyRef

    Permalink

    Do some magic to prefix path patterns with a single List

  6. trait RestHelper extends DispatchPF

    Permalink

    Mix this trait into a class to provide a list of REST helper methods

  7. trait XMLApiHelper extends AnyRef

    Permalink

    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

  1. object ContinuationsStore extends SessionVar[HashMap[ContinuationKey, Continuation]]

    Permalink
  2. object JsonSelect extends JsonXmlSelect with Product with Serializable

    Permalink

    The Type for JSON

  3. object RestContinuation

    Permalink

    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.

  4. object XmlSelect extends JsonXmlSelect with Product with Serializable

    Permalink

    The type for XML

Ungrouped