Module: Ksef::HTTP::Connection
- Defined in:
- lib/ksef/http/connection.rb
Overview
Builds the single Faraday connection a Client owns.
One connection per client, shared across threads — safe with the default net_http
adapter (DESIGN.md §5.2). The adapter is kept swappable via configuration.
Constant Summary collapse
- JSON_CONTENT_TYPE =
application/problem+jsonis the current error content type, so the response parser must match it as well as plainapplication/json(docs/REFERENCE.md §5.1). /\bjson\b/
Class Method Summary collapse
Class Method Details
.build(config) ⇒ Faraday::Connection
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ksef/http/connection.rb', line 20 def build(config) Faraday.new(url: config.base_url, headers: default_headers(config)) do |f| f.request :json # Registration order is load-bearing. Faraday runs `on_complete` callbacks # innermost-first, so the JSON parser must be registered *after* the error # handler for the handler to see a decoded body rather than a raw string. f.use ErrorHandler f.use SystemWarning, logger: config.logger f.response :json, content_type: JSON_CONTENT_TYPE (f, config) f.adapter config.adapter end end |