transparent_http

Types

pub type TransparentHttp(body, error) {
  TransparentHttp(
    setup_request: fn(Request(body)) -> Request(body),
    base_request: Request(body),
    sender: fn(Request(body)) -> Result(Response(body), error),
  )
}

Constructors

  • TransparentHttp(
      setup_request: fn(Request(body)) -> Request(body),
      base_request: Request(body),
      sender: fn(Request(body)) -> Result(Response(body), error),
    )
pub type TransparentHttpBuilder(body, error) {
  TransparentHttpBuilder(
    setup_request: Option(fn(Request(body)) -> Request(body)),
    base_request: Option(Request(body)),
    initial_req_body: body,
    sender: fn(Request(body)) -> Result(Response(body), error),
  )
}

Constructors

  • TransparentHttpBuilder(
      setup_request: Option(fn(Request(body)) -> Request(body)),
      base_request: Option(Request(body)),
      initial_req_body: body,
      sender: fn(Request(body)) -> Result(Response(body), error),
    )

    Arguments

    • setup_request

      Function that is applied to the base_request before being passed to the req function

    • base_request

      Base request for contant values e.g. auth headers

    • initial_req_body

      Initial value for request body, e.g. ""

    • sender

      Function that sends a request and gets a response

Functions

pub fn default(sender: fn(Request(a)) -> Result(Response(a), b), initial_request_body: a) -> TransparentHttp(
  a,
  b,
)

Creates a default TransparentHttp client

pub fn new(builder: TransparentHttpBuilder(a, b)) -> TransparentHttp(
  a,
  b,
)

Creates a new TransparentHttp client, taking overrides from the TransparentHttpBuilder

pub fn new_builder(sender: fn(Request(a)) ->
    Result(Response(a), b), initial_request_body: a) -> TransparentHttpBuilder(
  a,
  b,
)
pub fn req(client: TransparentHttp(a, b), request: fn(Request(a)) ->
    Request(a)) -> Result(Response(a), b)

Sends a request via the client’s sender, the flow is as follows:

  1. Take client’s base_request
  2. Pass to the setup_request function
  3. Pass to the request parameter
  4. Return the reponse from sender
Search Document