HTTP Client module

The HttpClient module provides HTTP client functionality for the Pillars application. It uses the http4s library for creating HTTP requests and handling HTTP responses.

HTTP Client Configuration

The HTTP client configuration is defined in the Config case class. It includes the following field:

  • followRedirect: A flag indicating whether to follow redirects.

The configuration is read from the application’s configuration file under the http-client section.

Using the HttpClient Module

To use the HttpClient module, you need to import it and then access it using the given Pillars instance:

import pillars.httpclient.*

http.get("some.uri.com") // with a `Pillars[IO]` in scope

HTTP Operations

The HttpClient module provides methods for sending HTTP requests and receiving HTTP responses. You can use the httpClient extension method on Pillars to get an instance of Client[F]:

import org.http4s.client.Client

val client: Client[F] = http.client

This Client[F] instance can be used to send HTTP requests by using the same methods as org.http4s.client.Client[F].

In addition to org.http4s.client.Client[F] methods, the HttpClient module provides methods to directly call a tapir endpoint:

  • call: Calls a tapir public endpoint with the specified input and returns either the output or the error output.

  • callSecure: Calls a tapir secure endpoint with the specified input and security input and returns either the output or the error output.

val client = summon[Pillars[F]].httpClient
val public: PublicEndpoint[Input, ErrorOutput, Output, Capabilities] = ???
val secure: Endpoint[SecurityInput, Input, ErrorOutput, Output, Capabilities] = ???

val uri: Option[Uri] = ???
val input: Input = ???
val securityInput: SecurityInput = ???

val output: F[Either[ErrorOutput, Output]] = client.call(public, uri)(input)
val secureOutput: F[Either[ErrorOutput, Output]] = client.callSecure(secure)(securityInput, input)

If an infrastructure error occurs, a HttpClient.Error will be thrown on the error channel.