Packages

  • package root
    Definition Classes
    root
  • package scamper

    At the core Scamper is HttpMessage, which is a trait that defines the fundamental characteristics of an HTTP message.

    HTTP Messages

    At the core Scamper is HttpMessage, which is a trait that defines the fundamental characteristics of an HTTP message. HttpRequest and HttpResponse extend the specification to define characteristics specific to their respective message types.

    An HttpRequest is created using one of the factory methods defined in its companion object. Or you can start with a RequestMethod and use builder methods to further define the request.

    import scamper.Header
    import scamper.Implicits.stringToUri
    import scamper.RequestMethods.GET
    
    val request = GET("/motd").withHeaders(
      Header("Host", "localhost:8080"),
      Header("Accept", "text/plain")
    )
    
    printf("Request Method: %s%n", request.method)
    printf("Target URI: %s%n", request.target)
    
    request.headers.foreach(println)
    
    val host: Option[String] = request.getHeaderValue("Host")

    An HttpResponse is created using one of the factory methods defined in its companion object. Or you can start with a ResponseStatus and use builder methods to further define the response.

    import scamper.{ BodyParsers, Header }
    import scamper.Implicits.stringToEntity
    import scamper.ResponseStatuses.Ok
    
    val response = Ok("There is an answer.").withHeaders(
      Header("Content-Type", "text/plain"),
      Header("Connection", "close")
    )
    
    printf("Status Code: %s%n", response.status.code)
    printf("Reason Phrase: %s%n", response.status.reason)
    
    response.headers.foreach(println)
    
    val contentType: Option[String] = response.getHeaderValue("Content-Type")
    
    implicit val parser = BodyParsers.text()
    
    printf("Body: %s%n", response.as[String])
    Definition Classes
    root
  • package cookies

    Provides specialized access to message cookies.

    Provides specialized access to message cookies.

    Request Cookies

    In HttpRequest, cookies are stringed together in the Cookie header. You can access them using the extension methods provided by RequestCookies, with each cookie represented as PlainCookie.

    import scamper.Implicits.stringToUri
    import scamper.RequestMethods.GET
    import scamper.cookies.{ PlainCookie, RequestCookies }
    
    // Build request with cookies
    val req = GET("https://localhost:8080/motd").withCookies(
      PlainCookie("ID", "bG9zCg"), PlainCookie("Region", "SE-US")
    )
    
    // Access and print all cookies
    req.cookies.foreach(println)
    
    // Get cookies by name
    val id: Option[PlainCookie] = req.getCookie("ID")
    val region: Option[PlainCookie] = req.getCookie("Region")
    
    // Get cookie values by name
    assert(req.getCookieValue("ID").contains("bG9zCg"))
    assert(req.getCookieValue("Region").contains("SE-US"))
    Response Cookies

    In HttpResponse, the cookies are a collection of Set-Cookie header values. Specialized access is provided by ResponseCookies, with each cookie represented as SetCookie.

    import scamper.Implicits.stringToEntity
    import scamper.ResponseStatuses.Ok
    import scamper.cookies.{ ResponseCookies, SetCookie }
    
    // Build response with cookies
    val res = Ok("There is an answer.").withCookies(
      SetCookie("ID", "bG9zCg", path = Some("/motd"), secure = true),
      SetCookie("Region", "SE-US")
    )
    
    // Access and print all cookies
    res.cookies.foreach(println)
    
    // Get cookies by name
    val id: Option[SetCookie] = res.getCookie("ID")
    val region: Option[SetCookie] = res.getCookie("Region")
    
    // Get attributes of ID cookie
    val path: String = id.flatMap(_.path).getOrElse("/")
    val secure: Boolean = id.map(_.secure).getOrElse(false)
    
    // Get cookie values by name
    assert(res.getCookieValue("ID").contains("bG9zCg"))
    assert(res.getCookieValue("Region").contains("SE-US"))
    Definition Classes
    scamper
  • Cookie
  • PlainCookie
  • RequestCookies
  • ResponseCookies
  • SetCookie
c

scamper.cookies

RequestCookies

implicit final class RequestCookies extends AnyVal

Provides access to request cookies in Cookie header.

Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RequestCookies
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new RequestCookies(request: HttpRequest)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def cookies: Seq[PlainCookie]

    Gets cookies.

  6. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  7. def getCookie(name: String): Option[PlainCookie]

    Gets specified cookie.

    Gets specified cookie.

    name

    cookie name

  8. def getCookieValue(name: String): Option[String]

    Gets value of specified cookie.

    Gets value of specified cookie.

    name

    cookie name

  9. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  10. def toString(): String
    Definition Classes
    Any
  11. def withCookie(cookie: PlainCookie): HttpRequest

    Creates copy of request with supplied cookie.

    Creates copy of request with supplied cookie.

    If a cookie already exists with given name, the existing cookie is replaced with the new cookie.

  12. def withCookies(cookies: PlainCookie*): HttpRequest

    Creates copy of request with new set of cookies.

    Creates copy of request with new set of cookies.

    cookies

    new set of cookies

Inherited from AnyVal

Inherited from Any

Ungrouped