View Source K8s.Client.Provider behaviour (k8s v2.0.0-rc.0)

HTTP Request / Response provider behaviour

Link to this section Summary

Callbacks

Perform HTTP requests and stream response

Perform Websocket requests and stream response

Functions

Generates HTTP headers from K8s.Conn.RequestOptions

Link to this section Types

@type error_t() :: {:error, K8s.Client.APIError.t() | K8s.Client.HTTPError.t()}
@type headers() :: [{header_name :: String.t(), header_value :: String.t()}]
@type response_t() :: success_t() | error_t()
@type stream_chunk_t() ::
  {:data | binary()}
  | {:status, integer()}
  | {:headers, headers()}
  | {:error, K8s.Client.HTTPError.t()}
  | :done
@type stream_response_t() :: stream_success_t() | error_t()
@type stream_success_t() :: {:ok, Enumerable.t(stream_chunk_t())}
@type success_t() :: {:ok, [map()] | map() | reference() | binary() | [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()}}

Link to this section 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 stream response

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 stream response

Link to this section 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

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"]