root package
package root
Provided herein is API documentation for Scamper, the HTTP library for Scala.
Package Members
- 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])
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.
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.