View Source Cosmox.RestClient (Cosmox v0.1.1)
Set of helpers to manage request and response management while interfacing with CosmosDB REST API.
Link to this section Summary
Functions
Decodes the response body, trying to parse it to the given struct.
Gets the error message when, while creating an object, there is a naming conflict.
Gets the error message obtained when the object was not found through the API.
Hides the response from the caller, preventing it from being leaked outside the scope of the API.
Perform the request to the CosmosDB REST API. Returns a common error that resumes both the client call and the deserialisation error.
Decodes the response body, trying to parse it to the given struct.
Link to this section Types
@type body() :: iodata() | {:stream, Enumerable.t()} | nil
@type headers() :: Mint.Types.headers()
@type method() :: :get | :post | :put | :patch | :delete
Link to this section Functions
@spec decode_response(response :: Finch.Response.t(), struct :: term(), list()) :: {:ok, term()} | {:error, Cosmox.Response.ErrorMessage.t()}
Decodes the response body, trying to parse it to the given struct.
List of options available through the opts
parameter:
- :error_handler: a function that accepts a status code and the body in a binary string form, and returns the type ErrorMessage.t()
@spec get_error_naming_conflict() :: binary()
Gets the error message when, while creating an object, there is a naming conflict.
@spec get_error_not_found_message() :: binary()
Gets the error message obtained when the object was not found through the API.
@spec handle_response_error(status :: non_neg_integer(), body :: binary()) :: {:error, Cosmox.Response.ErrorMessage.t()}
@spec hide_response( response :: {:ok, Finch.Response.t()} | {:error, Cosmox.Response.ErrorMessage.t()} ) :: :ok | {:error, Cosmox.Response.ErrorMessage.t()}
Hides the response from the caller, preventing it from being leaked outside the scope of the API.
@spec perform_request( method :: method(), url :: url(), headers :: headers(), body :: body() | binary() | nil ) :: {:ok, Finch.Response.t()} | {:error, Cosmox.Response.ErrorMessage.t()}
Perform the request to the CosmosDB REST API. Returns a common error that resumes both the client call and the deserialisation error.
@spec try_decode_response( response :: {:ok, Finch.Response.t()} | {:error, Cosmox.Response.ErrorMessage.t()}, struct :: term(), opts :: Keyword.t() ) :: {:ok, term()} | {:error, Cosmox.Response.ErrorMessage.t()}
Decodes the response body, trying to parse it to the given struct.
For the list of options for the opts keyword, refer to the method decode_response/3