gleam/httpc
Types
Configuration that can be used to send HTTP requests.
To be used with dispatch
and dispatch_bits
.
pub opaque type Configuration
pub type ConnectError {
Posix(code: String)
TlsAlert(code: String, detail: String)
}
Constructors
-
Posix(code: String)
-
TlsAlert(code: String, detail: String)
pub type HttpError {
InvalidUtf8Response
FailedToConnect(ip4: ConnectError, ip6: ConnectError)
ResponseTimeout
}
Constructors
-
InvalidUtf8Response
The response body contained non-UTF-8 data, but UTF-8 data was expected.
-
FailedToConnect(ip4: ConnectError, ip6: ConnectError)
It was not possible to connect to the host.
-
ResponseTimeout
The response was not received within the configured timeout period.
Values
pub fn configure() -> Configuration
Create a new configuration with the default settings.
Defaults
- TLS is verified.
- Redirects are not followed.
- The timeout for the response to be received is 30 seconds from when the request is sent.
pub fn dispatch(
config: Configuration,
request: request.Request(String),
) -> Result(response.Response(String), HttpError)
Send a HTTP request of unicode data.
pub fn dispatch_bits(
config: Configuration,
req: request.Request(BitArray),
) -> Result(response.Response(BitArray), HttpError)
Send a HTTP request of binary data.
pub fn follow_redirects(
config: Configuration,
which: Bool,
) -> Configuration
Set whether redirects should be followed automatically.
pub fn send(
req: request.Request(String),
) -> Result(response.Response(String), HttpError)
Send a HTTP request of unicode data using the default configuration.
If you wish to use some other configuration use dispatch
instead.
pub fn send_bits(
req: request.Request(BitArray),
) -> Result(response.Response(BitArray), HttpError)
Send a HTTP request of binary data using the default configuration.
If you wish to use some other configuration use dispatch_bits
instead.
pub fn timeout(
config: Configuration,
timeout: Int,
) -> Configuration
Set the timeout in milliseconds, the default being 30 seconds.
If the response is not recieved within this amount of time then the client disconnects and an error is returned.
pub fn verify_tls(
config: Configuration,
which: Bool,
) -> Configuration
Set whether to verify the TLS certificate of the server.
This defaults to True
, meaning that the TLS certificate will be verified
unless you call this function with False
.
Setting this to False
can make your application vulnerable to
man-in-the-middle attacks and other security risks. Do not do this unless
you are sure and you understand the risks.