spray
latest
  • Introduction
  • Documentation
    • spray-caching
    • spray-can
    • spray-client
    • spray-http
    • spray-httpx
    • spray-io
    • spray-routing
      • Dependencies
      • Installation
      • Configuration
      • Getting Started
      • Key Concepts
      • Advanced Topics
      • Predefined Directives (alphabetically)
      • Predefined Directives (by trait)
        • Directives filtering or extracting from the request
        • Directives creating or transforming the response
        • List of predefined directives by trait
      • Complete Examples
      • Minimal Example
      • Longer Example
    • spray-servlet
    • spray-testkit
    • spray-util
  • Project Info
  • Blog
  • Contact
spray
  • Docs »
  • Documentation »
  • spray-routing »
  • Predefined Directives (by trait) »
  • CookieDirectives »
  • cookie
  • Edit on GitHub

cookie

Extracts a cookie with a given name from a request or otherwise rejects the request with a MissingCookieRejection if the cookie is missing.

Signature

def cookie(name: String): Directive1[HttpCookie] 

Description

Use the optionalCookie directive instead if you want to support missing cookies in your inner route.

Example

val route =
  cookie("userName") { nameCookie =>
    complete(s"The logged in user is '${nameCookie.content}'")
  }


Get("/") ~> Cookie(HttpCookie("userName", "paul")) ~> route ~> check {
  responseAs[String] === "The logged in user is 'paul'"
}
// missing cookie
Get("/") ~> route ~> check {
  rejection === MissingCookieRejection("userName")
}
Get("/") ~> sealRoute(route) ~> check {
  responseAs[String] === "Request is missing required cookie 'userName'"
}
Next Previous

© Copyright 2011-2015 spray.io.. Revision 76ab89c2.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.