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 can be 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 can be 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 types

    Defines standardized types for header classes in scamper.headers.

    Defines standardized types for header classes in scamper.headers.

    import scamper.Implicits.{ stringToEntity, stringToUri }
    import scamper.RequestMethods.GET
    import scamper.ResponseStatuses.Ok
    import scamper.headers.{ Accept, ContentType, TransferEncoding }
    import scamper.types.{ MediaRange, MediaType, TransferCoding }
    
    val json = MediaRange("application", "json", 0.9f)
    val html = MediaRange.parse("text/html; q=0.1")
    
    val req = GET("/motd").withAccept(json, html)
    
    val text = MediaType.parse("text/plain")
    val gzip = TransferCoding("gzip")
    
    val res = Ok("There is an answer.").withContentType(text).withTransferEncoding(gzip)

    Using values defined in Implicits, properly formatted strings can be implicitly converted to standardized types.

    import scamper.Implicits.{ stringToEntity, stringToUri }
    import scamper.RequestMethods.GET
    import scamper.ResponseStatuses.Ok
    import scamper.headers.{ Accept, ContentType, TransferEncoding }
    import scamper.types.Implicits._
    
    val req = GET("/motd").withAccept("application/json; q=0.9", "text/html; q=0.1")
    
    val res = Ok("There is an answer.").withContentType("text/plain").withTransferEncoding("gzip")
    Definition Classes
    scamper
  • ByteContentRange
  • ByteRange
  • CacheDirective
  • CacheDirectives
  • CharsetRange
  • ContentCoding
  • ContentCodingRange
  • ContentRangeType
  • DispositionType
  • EntityTag
  • Implicits
  • LanguageRange
  • LanguageTag
  • LinkValue
  • MediaRange
  • MediaType
  • PragmaDirective
  • PragmaDirectives
  • Preference
  • Preferences
  • ProductType
  • Protocol
  • RangeType
  • TransferCoding
  • TransferCodingRange
  • ViaType
  • WarningType

trait MediaRange extends AnyRef

Standardized type for Accept header value.

See also

scamper.headers.Accept

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

Abstract Value Members

  1. abstract def mainType: String

    Gets main type of media range.

  2. abstract def matches(mediaType: MediaType): Boolean

    Tests whether supplied media type matches range.

  3. abstract def params: Map[String, String]

    Gets media range parameters.

  4. abstract def subtype: String

    Gets subtype of media range.

  5. abstract def weight: Float

    Gets weight of media range.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def isApplication: Boolean

    Tests whether main type is application.

  12. def isAudio: Boolean

    Tests whether main type is audio.

  13. def isFont: Boolean

    Tests whether main type is font.

  14. def isImage: Boolean

    Tests whether main type is image.

  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. def isMessage: Boolean

    Tests whether main type is message.

  17. def isMultipart: Boolean

    Tests whether main type is multipart.

  18. def isText: Boolean

    Tests whether main type is text.

  19. def isVideo: Boolean

    Tests whether main type is video.

  20. def isWildcard: Boolean

    Tests whether main type is wildcard (*).

  21. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  25. lazy val toString: String

    Returns formatted media range.

    Returns formatted media range.

    Definition Classes
    MediaRange → AnyRef → Any
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  28. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped