Defines HTTP client.
A client can be created using the HttpClient companion object.
import scala.language.implicitConversions
import scamper.http.{ BodyParser, stringToUri }
import scamper.http.client.HttpClient
given BodyParser[String] = BodyParser.string()
// Create HttpClient instance
val client = HttpClient()
def getMessageOfTheDay(): Either[Int, String] =
// Use client instance
client.get("http://localhost:8080/motd") { res =>
res.isSuccessful match
case true => Right(res.as[String])
case false => Left(res.statusCode)
}
And, if a given client is in scope, you can make use of send()
on the request itself.
import scala.language.implicitConversions
import scamper.http.{ BodyParser, stringToUri }
import scamper.http.RequestMethod.Registry.Get
import scamper.http.client.{ HttpClient, toClientHttpRequest }
import scamper.http.headers.{ toAccept, toAcceptLanguage }
import scamper.http.types.{ stringToMediaRange, stringToLanguageRange }
given HttpClient = HttpClient()
given BodyParser[String] = BodyParser.string(4096)
Get("http://localhost:8080/motd")
.setAccept("text/plain")
.setAcceptLanguage("en-US; q=0.6", "fr-CA; q=0.4")
.send(res => println(res.as[String])) // Send request using client
See also ClientSettings for information about configuring the HTTP client before it is created.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Abstract methods
Gets accepted content types.
Gets accepted content types.
Attributes
Gets accepted encodings.
Gets accepted encodings.
Attributes
Gets buffer size.
Gets buffer size.
Attributes
Gets continue timeout.
Gets continue timeout.
Attributes
Gets cookie store.
Gets cookie store.
Attributes
Sends DELETE request and passes response to handler.
Sends DELETE request and passes response to handler.
Value parameters
- cookies
-
request cookies
- handler
-
response handler
- headers
-
request headers
- target
-
request target
Attributes
- Returns
-
value from response handler
- Throws
-
java.lang.IllegalArgumentException
if
target
is not absolute
Sends GET request and passes response to handler.
Sends GET request and passes response to handler.
Value parameters
- cookies
-
request cookies
- handler
-
response handler
- headers
-
request headers
- target
-
request target
Attributes
- Returns
-
value from response handler
- Throws
-
java.lang.IllegalArgumentException
if
target
is not absolute
Tests whether persistent connections are enabled.
Tests whether persistent connections are enabled.
Attributes
Sends POST request and passes response to handler.
Sends POST request and passes response to handler.
Value parameters
- body
-
message body
- cookies
-
request cookies
- handler
-
response handler
- headers
-
request headers
- target
-
request target
Attributes
- Returns
-
value from response handler
- Throws
-
java.lang.IllegalArgumentException
if
target
is not absolute
Sends PUT request and passes response to handler.
Sends PUT request and passes response to handler.
Value parameters
- body
-
message body
- cookies
-
request cookies
- handler
-
response handler
- headers
-
request headers
- target
-
request target
Attributes
- Returns
-
value from response handler
- Throws
-
java.lang.IllegalArgumentException
if
target
is not absolute
Gets read timeout.
Gets read timeout.
Attributes
Sends request and passes response to supplied handler.
Sends request and passes response to supplied handler.
Value parameters
- handler
-
response handler
- request
-
outgoing request
Attributes
- Returns
-
value from response handler
- Throws
-
java.lang.IllegalArgumentException
if
request.target
is not absolute
Connects to WebSocket server at target path and passes established session to supplied application.
Connects to WebSocket server at target path and passes established session to supplied application.
Value parameters
- application
-
WebSocket application
- cookies
-
cookies to include in WebSocket request
- headers
-
additional headers to include in WebSocket request
- target
-
WebSocket target
Attributes
- Returns
-
value from application
- Throws
-
java.lang.IllegalArgumentException
if
target
is not WebSocket URI (i.e., it must be absolute URI with either "ws" or "wss" scheme)scamper.http.websocket.WebSocketHandshakeFailureif WebSocket handshake fails