5.1 Introduction
Lift gives you access to low level HTTP requests, either within the scope of an session or outside the scope of a session. In sessionless or stateless mode, Lift does not use the container’s session management machinery to add a cookie to the
HTTP response and does not make
SessionVar or
ContainerVar available during the request. Stateless REST requests do not require session affinity. Authentication for stateless REST handling can be done via
OAuth. If the requests are handled statefully, a container session will be created if the
JSESSIONID cookie is not supplied as part of the request and the
JSESSIONID cookie will be included with the response.
Lift makes use of Scala’s pattern matching to allow you match incoming HTTP requests, extract values as part of the pattern matching process and return the results. Scala’s pattern matching is very, very powerful. It allows both the declaration of a pattern that must be matched, wildcard values (a sub-expression may match any supplied value), wildcard values extracted into variables, and explicit extractors (imperative logic applied to a value to determine if it should match and if it does, extract it into a variable). Lift tests a Scala PartialFunction[Req, () => Box[LiftResponse]] to see if it is defined for a given Req, which represents an HTTP request. If there is a match, Lift will take the resulting function, apply it to get a Box[LiftResponse] and if the Box is full, the response will be sent back to the browser. That’s a mouth-full. Let’s look at examples.
(C) 2012 David Pollak