View Source K8s.Client.Provider behaviour (k8s v2.6.1)
HTTP Request / Response provider behaviour
Summary
Callbacks
Perform HTTP requests
Perform HTTP requests and returns a stream of response chunks
Perform HTTP requests and stream response to another process
Perform HTTP requests
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 http_chunk_t() :: {:data | binary()} | {:status, integer()} | {:headers, headers()} | {:error, K8s.Client.HTTPError.t()} | :done
@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())}
@type stream_to_response_t() :: {:ok, send_callback()} | :ok | error_t()
@type websocket_response_t() :: websocket_success_t() | error_t()
Callbacks
@callback request( method :: atom(), uri :: URI.t(), body :: binary(), headers :: list(), http_opts :: keyword() ) :: response_t()
Perform HTTP requests
@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
@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
@callback websocket_request( uri :: URI.t(), headers :: list(), http_opts :: keyword() ) :: websocket_response_t()
Perform HTTP requests
@callback websocket_stream( uri :: URI.t(), headers :: list(), http_opts :: keyword() ) :: stream_response_t()
Perform websocket requests and returns a stream of response chunks
@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"]