lustre_http

Types

pub type HttpError {
  Unauthorized
  NotFound
  InternalServerError(String)
  OtherError(Int, String)
}

Constructors

  • Unauthorized
  • NotFound
  • InternalServerError(String)
  • OtherError(Int, String)
pub type HttpOrJsonError {
  H(HttpError)
  J(json.DecodeError)
}

Constructors

  • H(HttpError)
  • J(json.DecodeError)
pub type JsonResult(t) =
  Result(t, HttpOrJsonError)
pub type StringResult =
  Result(String, HttpError)

Functions

pub fn get_as_json(url: String, to_msg: fn(
    Result(String, HttpOrJsonError),
  ) -> a, decoder: fn(Dynamic) ->
    Result(String, List(DecodeError))) -> Cmd(a)
pub fn get_as_text(url: String, to_msg: fn(
    Result(String, HttpError),
  ) -> a) -> Cmd(a)

Usage

import lustre_http as http

type Msg {
  SomeInteraction
  TextReceived(StringResult)
}

pub fn update(model, msg) {
  case msg {
    SomeInteraction -> #(model, http.get_as_text("the_text", TextReceived))
    TextReceived(Ok(text)) -> #(apply(text, model), cmd.none())
    TextReceived(Error(e)) -> #(indicate_problem(e, model), cmd.none())
  }
}
pub fn post_text(url: String, body: String, to_msg: fn(
    Result(String, HttpError),
  ) -> a) -> Cmd(a)
Search Document