transparent_http

Types

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

Constructors

  • SimpleHttp(
      setup_request: fn(Request(body)) -> Request(body),
      base_request: Request(body),
      sender: fn(Request(body)) -> Response(body),
    )
pub type SimpleHttpBuilder(body) {
  SimpleHttpBuilder(
    setup_request: Option(fn(Request(body)) -> Request(body)),
    base_request: Option(Request(body)),
    initial_req_body: body,
    sender: fn(Request(body)) -> Response(body),
  )
}

Constructors

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

    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)) -> Response(a), initial_request_body: a) -> SimpleHttp(
  a,
)

Creates a default SimpleHttp client

pub fn new(builder: SimpleHttpBuilder(a)) -> SimpleHttp(a)

Creates a new SimpleHttp client, taking overrides from the SimpleHttpBuilder

pub fn new_builder(sender: fn(Request(a)) -> Response(a), initial_request_body: a) -> SimpleHttpBuilder(
  a,
)
pub fn req(client: SimpleHttp(a), request: fn(Request(a)) ->
    Request(a)) -> Response(a)

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