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
  • object Implicits

    Includes implicit converter functions and type classes.

    Includes implicit converter functions and type classes.

    Definition Classes
    scamper
  • HttpMessageType
c

scamper.Implicits

HttpMessageType

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

Adds extension methods to HttpMessage for building messages with various content types.

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

Instance Constructors

  1. new HttpMessageType(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 getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  6. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  7. def setFileBody(file: File)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with content from supplied file as message body.

    Creates new message with content from supplied file as message body.

    After adding body to message, the Content-Type header is set based on file type, and Content-Length is set to file size.

    file

    message body

  8. def setFormBody(query: QueryString)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied query string as message body.

    Creates new message with supplied query string as message body.

    After adding body to message, the Content-Type header is set to application/x-www-form-urlencoded, and Content-Length is set to length of encoded query string.

    query

    message body

  9. def setFormBody(one: (String, String), more: (String, String)*)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied form data as message body.

    Creates new message with supplied form data as message body.

    After adding body to message, the Content-Type header is set to application/x-www-form-urlencoded, and Content-Length is set to length of encoded form data.

    one

    form data

    more

    additional form data

  10. def setFormBody(data: Seq[(String, String)])(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied form data as message body.

    Creates new message with supplied form data as message body.

    After adding body to message, the Content-Type header is set to application/x-www-form-urlencoded, and Content-Length is set to length of encoded form data.

    data

    message body

  11. def setFormBody(data: Map[String, Seq[String]])(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied form data as message body.

    Creates new message with supplied form data as message body.

    After adding body to message, the Content-Type header is set to application/x-www-form-urlencoded, and Content-Length is set to length of encoded form data.

    data

    message body

  12. def setMultipartBody(one: Part, more: Part*)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied parts as message body, with the parts encoded as multipart form data.

    Creates new message with supplied parts as message body, with the parts encoded as multipart form data.

    After adding body to message, the Content-Type header is set to multipart/form-data with a boundary parameter whose value is used to delimit parts in encoded message body.

    one

    part

    more

    additional parts

  13. def setMultipartBody(parts: Seq[Part])(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied parts as message body, with the parts encoded as multipart form data.

    Creates new message with supplied parts as message body, with the parts encoded as multipart form data.

    After adding body to message, the Content-Type header is set to multipart/form-data with a boundary parameter whose value is used to delimit parts in encoded message body.

    parts

    message body

  14. def setMultipartBody(multipart: Multipart)(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied multipart as message body.

    Creates new message with supplied multipart as message body.

    After adding body to message, the Content-Type header is set to multipart/form-data with a boundary parameter whose value is used to delimit parts in encoded message body.

    multipart

    message body

  15. def setTextBody(text: String, charset: String = "UTF-8")(implicit ev: <:<[T, MessageBuilder[T]]): T

    Creates new message with supplied text as message body.

    Creates new message with supplied text as message body.

    After adding body to message, the Content-Type header is set to text/plain with its charset parameter set accordingly, and Content-Length is set to length of encoded characters.

    text

    message body

    charset

    character set

  16. def toString(): String
    Definition Classes
    Any

Inherited from AnyVal

Inherited from Any

Ungrouped