Tinkex.API.Request (Tinkex v0.3.4)

View Source

Request preparation and body encoding for Tinkex API.

Handles:

  • JSON body encoding
  • Multipart/form-data encoding for file uploads
  • Request body preparation and validation
  • Content-type header management

Summary

Functions

Formats error reasons from request preparation into human-readable messages.

Prepares the request body and updates headers as needed.

Functions

format_error(reason)

@spec format_error(term()) :: String.t()

Formats error reasons from request preparation into human-readable messages.

prepare_body(body, headers, files, transform_opts)

@spec prepare_body(term(), [{String.t(), String.t()}], term(), keyword()) ::
  {:ok, [{String.t(), String.t()}], iodata()} | {:error, term()}

Prepares the request body and updates headers as needed.

For multipart requests (with files), encodes as multipart/form-data. For regular requests, encodes body as JSON.

Returns {:ok, headers, body} or {:error, reason}.