gleam/http/response

Types

pub type Response(body) {
  Response(status: Int, headers: List(Header), body: body)
}

Constructors

  • Response(status: Int, headers: List(Header), body: body)

Functions

pub fn expire_cookie(response: Response(a), name: String, attributes: Attributes) -> Response(
  a,
)

Expire a cookie value for a client

Note: The attributes value should be the same as when the response cookie was set.

pub fn get_cookies(resp: Response(a)) -> List(#(String, String))

Fetch the cookies sent in a response.

Badly formed cookies will be discarded.

pub fn get_header(response: Response(a), key: String) -> Result(
  String,
  Nil,
)

Get the value for a given header.

If the request does not have that header then Error(Nil) is returned.

pub fn map(response: Response(a), transform: fn(a) -> b) -> Response(
  b,
)

Update the body of a response using a given function.

pub fn new(status: Int) -> Response(String)

Construct an empty Response.

The body type of the returned response is String and could be set with a call to set_body.

pub fn prepend_header(response: Response(a), key: String, value: String) -> Response(
  a,
)
pub fn redirect(uri: String) -> Response(String)

Create a response that redirects to the given uri.

pub fn set_body(response: Response(a), body: b) -> Response(b)

Set the body of the response, overwriting any existing body.

pub fn set_cookie(response: Response(a), name: String, value: String, attributes: Attributes) -> Response(
  a,
)

Set a cookie value for a client

pub fn try_map(response: Response(a), transform: fn(a) ->
    Result(b, c)) -> Result(Response(b), c)

Update the body of a response using a given result returning function.

If the given function returns an Ok value the body is set, if it returns an Error value then the error is returned.