Http
Request
Represents an HTTP request.
Method
Represents an HTTP method.
Header
Represents an HTTP header e.g. Content-Type: application/json
TimeoutConfig
Represents a timeout configuration for an HTTP request.
Response
Represents an HTTP response.
Err
Represents an HTTP error.
errorBodyToBytes
Convert the ErrorBody of a BadStatus error to List U8.
defaultRequest : Request
A default Request
value.
# GET "roc-lang.org" { Http.defaultRequest & url: "https://www.roc-lang.org", }
header : Str, Str -> Header
An HTTP header for configuring requests.
See common headers here.
handleStringResponse : Response -> Result Str Err
errorToString : Err -> Str
send : Request -> Task Response [HttpErr Err]
Task to send an HTTP request, succeeds with a value of Str
or fails with an
Err
.
# Prints out the HTML of the Roc-lang website. response = { Http.defaultRequest & url: "https://www.roc-lang.org" } |> Http.send! response.body |> Str.fromUtf8 |> Result.withDefault "Invalid UTF-8" |> Stdout.line
get : Str, fmt -> Task body [ HttpErr Http.Err, HttpDecodingFailed ] where body implements Decoding, fmt implements DecoderFormatting
Try to perform an HTTP get request and convert (decode) the received bytes into a Roc type. Very useful for working with Json.
import json.Json # On the server side we send `Encode.toBytes {foo: "Hello Json!"} Json.utf8` { foo } = Http.get! "http://localhost:8000" Json.utf8