Gleanex.HTTP (Gleanex v0.1.0)

Copy Markdown View Source

The transport behind every generated operation.

Generated operation functions end in a call to request/1 with a description of the call. This module turns that description into a Req request, sends it, and normalises the result to {:ok, term} or {:error, Gleanex.Error.t()}.

Per call options

Every generated operation takes a trailing opts keyword list. Alongside the operation's own query parameters it understands:

  • :config - the Gleanex.Config to use. Falls back to Gleanex.Config.default/0, which reads the application and system environment.
  • :receive_timeout - override the config's timeout for this call.
  • :retry - override the config's Gleanex.Retry policy for this call.
  • :req_options - extra Req options, merged over the config's.
  • :client - swap this module out entirely, handled by the generated code.

Telemetry

Each request emits a span under [:gleanex, :request]:

  • [:gleanex, :request, :start] with %{system_time: integer}
  • [:gleanex, :request, :stop] with %{duration: integer}
  • [:gleanex, :request, :exception] with %{duration: integer}

Metadata carries :api, :operation, :method and :url, and the stop event adds :status or :error.

Summary

Functions

Which of the four APIs an operation module belongs to.

Build the Req request for an operation without sending it.

Run a generated operation description.

Functions

api_for(module)

@spec api_for({module(), atom()} | module() | nil) :: Gleanex.Config.api()

Which of the four APIs an operation module belongs to.

Derived from the module name, so Gleanex.Indexing.Documents resolves to :indexing. Unrecognised modules fall back to :client.

build_request(config, api, operation)

@spec build_request(Gleanex.Config.t(), Gleanex.Config.api(), map()) ::
  Req.Request.t()

Build the Req request for an operation without sending it.

Exposed for Gleanex.Streaming, which needs the same URL, auth and retry handling but has to consume the response body as it arrives rather than all at once. Options under the operation's :opts are applied last, so a caller can add into: :self through req_options.

request(operation)

@spec request(map()) :: {:ok, term()} | {:error, Gleanex.Error.t()}

Run a generated operation description.