View Source K8s.Client.Provider behaviour (k8s v2.6.0)

HTTP Request / Response provider behaviour

Summary

Callbacks

Perform HTTP requests and returns a stream of response chunks

Perform HTTP requests and stream response to another process

Perform websocket requests and returns a stream of response chunks

Perform websocket requests and returns a stream of response chunks

Functions

Generates HTTP headers from K8s.Conn.RequestOptions

Types

@type error_t() :: {:error, K8s.Client.APIError.t() | K8s.Client.HTTPError.t()}
@type headers() :: [{header_name :: String.t(), header_value :: String.t()}]
@type http_chunk_t() ::
  {:data | binary()}
  | {:status, integer()}
  | {:headers, headers()}
  | {:error, K8s.Client.HTTPError.t()}
  | :done
@type response_t() :: success_t() | error_t()
@type send_callback() :: (any() -> :ok)
@type stream_response_t() :: stream_success_t() | error_t()
@type stream_success_t() :: {:ok, Enumerable.t(http_chunk_t() | websocket_chunk_t())}
Link to this type

stream_to_response_t()

View Source
@type stream_to_response_t() :: {:ok, send_callback()} | :ok | error_t()
@type success_t() :: {:ok, [map()] | map() | reference() | binary() | [binary()]}
@type websocket_chunk_t() ::
  {:stdout, binary()}
  | {:stderr, binary()}
  | {:error, binary()}
  | {:close, {integer(), binary()}}
Link to this type

websocket_response_t()

View Source
@type websocket_response_t() :: websocket_success_t() | error_t()
@type websocket_success_t() ::
  {:ok, %{stdin: binary(), stderr: binary(), error: binary()}}

Callbacks

Link to this callback

request(method, uri, body, headers, http_opts)

View Source
@callback request(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword()
) :: response_t()

Perform HTTP requests

Link to this callback

stream(method, uri, body, headers, http_opts)

View Source
@callback stream(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword()
) :: stream_response_t()

Perform HTTP requests and returns a stream of response chunks

Link to this callback

stream_to(method, uri, body, headers, http_opts, stream_to)

View Source
@callback stream_to(
  method :: atom(),
  uri :: URI.t(),
  body :: binary(),
  headers :: list(),
  http_opts :: keyword(),
  stream_to :: pid()
) :: stream_to_response_t()

Perform HTTP requests and stream response to another process

Link to this callback

websocket_request(uri, headers, http_opts)

View Source
@callback websocket_request(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword()
) :: websocket_response_t()

Perform HTTP requests

Link to this callback

websocket_stream(uri, headers, http_opts)

View Source
@callback websocket_stream(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword()
) :: stream_response_t()

Perform websocket requests and returns a stream of response chunks

Link to this callback

websocket_stream_to(uri, headers, http_opts, stream_to)

View Source
@callback websocket_stream_to(
  uri :: URI.t(),
  headers :: list(),
  http_opts :: keyword(),
  stream_to :: pid()
) :: stream_to_response_t()

Perform websocket requests and returns a stream of response chunks

Functions

@spec headers(K8s.Conn.RequestOptions.t()) :: keyword()

Generates HTTP headers from K8s.Conn.RequestOptions

  • Adds {:Accept, "application/json"} to all requests if the header is not set.

Examples

Sets Content-Type to application/json

iex> opts = %K8s.Conn.RequestOptions{headers: [Authorization: "Basic AF"]}
...> K8s.Client.HTTPProvider.headers(opts)
[Accept: "application/json", Authorization: "Basic AF"]