-
Notifications
You must be signed in to change notification settings - Fork 7
HTTP Client
Matt Muller edited this page Apr 10, 2024
·
8 revisions
The HTTP client is a class that handles transmission of a Request object over the network and populates a Response object.
Hearth provides a default HTTP client implemented using Ruby's Net::HTTP
. The HTTP client takes many options related to wire trace output, various timeouts, SSL verify, certificate authorities, DNS host resolving options, etc.
http_client = Hearth::HTTP::Client.new(read_timeout: 1, debug_output: true)
# => #<Hearth::HTTP ... >
client = HighScoreService::Client.new(
endpoint: 'http://127.0.0.1:3000',
http_client: http_client
)
# => #<HighScoreService ... >
client.list_high_scores
# <Uses HTTP client with wire trace logging to send>
# GET /high_scores ...
# => #<Hearth::Output @data=... >
A custom implemented HTTP client can be provided as long as it implements a transmit(request:, response:, logger: nil)
method. Implementations can use whatever transport library it would like, such as raw sockets, curb, Faraday, etc. The method must populate the Response object with headers, body, status, etc. If an networking issue occurs, a Hearth::NetworkingError
should be raised.