Packages

  • package root

    Provided herein is API documentation for Scamper, the HTTP library for Scala.

    Provided herein is API documentation for Scamper, the HTTP library for Scala.

    Definition Classes
    root
  • package scamper

    Defines core types.

    Defines core types.

    HTTP Messages

    At the core of 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 a factory method 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.RequestMethod.Registry.Get
    
    val request = Get("/motd").setHeaders(
      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 a factory method defined in its companion object. Or you can start with a ResponseStatus and use builder methods to further define the response.

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

    Provides specialized access to message headers.

    Provides specialized access to message headers.

    Using Header Classes

    Specialized header access is provided by type classes. Some headers are available to both requests and responses, and others are available only to a specific message type. This behavior is driven by the HTTP specification.

    import scamper.Implicits.stringToUri
    import scamper.RequestMethod.Registry.Get
    import scamper.headers.{ Accept, Host }
    import scamper.types.Implicits.stringToMediaRange
    
    // Build request using 'Host' and 'Accept' headers
    val req = Get("/motd")
      .setHost("localhost:8080")
      .setAccept("text/plain")
    
    // Access and print header values
    printf("Host: %s%n", req.host)
    printf("Accept: %s%n", req.accept.mkString(", "))
    Definition Classes
    scamper
  • Accept
  • AcceptCharset
  • AcceptEncoding
  • AcceptLanguage
  • AcceptPatch
  • AcceptRanges
  • Age
  • Allow
  • CacheControl
  • Connection
  • ContentDisposition
  • ContentEncoding
  • ContentLanguage
  • ContentLength
  • ContentLocation
  • ContentRange
  • ContentType
  • Date
  • ETag
  • EarlyData
  • Expect
  • Expires
  • From
  • Host
  • IfMatch
  • IfModifiedSince
  • IfNoneMatch
  • IfRange
  • IfUnmodifiedSince
  • KeepAlive
  • LastModified
  • Link
  • Location
  • MaxForwards
  • Pragma
  • Prefer
  • PreferenceApplied
  • Range
  • Referer
  • RetryAfter
  • Server
  • TE
  • Trailer
  • TransferEncoding
  • Upgrade
  • UserAgent
  • Vary
  • Via
  • Warning
c

scamper.headers

CacheControl

implicit final class CacheControl[T <: HttpMessage] extends AnyVal

Provides standardized access to Cache-Control header.

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

Instance Constructors

  1. new CacheControl(message: T)

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 cacheControl: Seq[CacheDirective]

    Gets Cache-Control header values.

    Gets Cache-Control header values.

    returns

    header values or empty sequence if Cache-Control is not present

  6. def getCacheControl: Option[Seq[CacheDirective]]

    Gets Cache-Control header values if present.

  7. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  8. def hasCacheControl: Boolean

    Tests for Cache-Control header.

  9. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  10. def removeCacheControl(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message removing Cache-Control header.

  11. def setCacheControl(one: CacheDirective, more: CacheDirective*)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message setting Cache-Control header to supplied values.

  12. def setCacheControl(values: Seq[CacheDirective])(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message setting Cache-Control header to supplied values.

  13. def toString(): String
    Definition Classes
    Any

Inherited from AnyVal

Inherited from Any

Ungrouped