http
Types
Body
Empty
Text(Str)
HttpError
ConnectionError(Str)
Timeout
Method
GET
POST
PUT
DELETE
PATCH
HEAD
OPTIONS
Request
Request(Method, Str, List<(Str, Str)>, Body)
Response
Response(Int, List<(Str, Str)>, Body)
Effects
Send
The Send effect for HTTP clients.
fn(req: Request) -> Response / { Send, Raise<HttpError> }
Serve
The Serve effect for HTTP servers.
Request / { Serve }
fn(req: Request, res: Response) -> () / { Serve }
Functions
bad_request
fn(body_str: Str) -> Response
Create a 400 Bad Request response with a text body.
body_text
fn(res: Response) -> Str
Get the body as text. Returns empty string for Empty bodies.
created
fn(body_str: Str) -> Response
Create a 201 Created response with a text body.
delete
fn(url: Str) -> Request
Create a DELETE request.
get
fn(url: Str) -> Request
Create a GET request.
head
fn(url: Str) -> Request
Create a HEAD request.
is_ok
fn(res: Response) -> Bool
Check if a response status is in the 2xx range.
method_to_string
fn(method: Method) -> Str
Convert a Method to its string representation.
no_content
fn () -> Response
Create a 204 No Content response with an empty body.
not_found
fn(body_str: Str) -> Response
Create a 404 Not Found response with a text body.
ok
fn(body_str: Str) -> Response
Create a 200 OK response with a text body.
options
fn(url: Str) -> Request
Create an OPTIONS request.
patch
fn(url: Str) -> Request
Create a PATCH request.
post
fn(url: Str) -> Request
Create a POST request.
put
fn(url: Str) -> Request
Create a PUT request.
redirect
fn(url: Str) -> Response
Create a 302 redirect response with a Location header.
request
fn(method: Method, url: Str) -> Request
Create a request with the given method and URL.
response
fn(status: Int, body_str: Str) -> Response
Create a response with the given status and text body.
string_to_method
fn(s: Str) -> Method
Convert a string (e.g. "GET") to a Method. Defaults to GET for unknown strings.
with_body
fn(req: Request, new_body: Body) -> Request
Set the body of a request.
with_header
fn(req: Request, name: Str, value: Str) -> Request
Append a header to a request.
with_response_header
fn(res: Response, name: Str, value: Str) -> Response
Append a header to a response.
with_status
fn(res: Response, new_status: Int) -> Response
Set the status code of a response.
with_text
fn(req: Request, text: Str) -> Request
Set a text body on a request.