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.
Metadata
Represents HTTP metadata, such as the URL or status code.
Error
Represents an HTTP error.
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 Error
errorToString : Error -> Str
send : Request -> Task Str Error
Task to send an HTTP request, succeeds with a value of Str
or fails with an
Error
.
# Prints out the HTML of the Roc-lang website. result <- { Http.defaultRequest & url: "https://www.roc-lang.org", } |> Http.send |> Task.attempt when result is Ok responseBody -> Stdout.line responseBody Err _ -> Stdout.line "Oops, something went wrong!"
getUtf8 : Str -> Task Str Error
methodToStr : Method -> Str
parseFormUrlEncoded : List U8 -> Result (Dict Str Str) [BadUtf8]
Parse URL-encoded form values (todo=foo&status=bar
) into a Dict (("todo", "foo"), ("status", "bar")
).
expect bytes = Str.toUtf8 "todo=foo&status=bar" parsed = parseFormUrlEncoded bytes |> Result.withDefault (Dict.empty {}) Dict.toList parsed == [("todo", "foo"), ("status", "bar")]