Using as an http4s client¶
Add the dependency:
"com.softwaremill.sttp.tapir" %% "tapir-http4s-client" % "0.18.0-M1"
To interpret an endpoint definition as an
This objects contains two methods:
toRequestUnsafe(Endpoint, Option[String]): given the optional base URI, returns a function which generates a request and a response parser from endpoint inputs. Response parser throws an exception if decoding of the result fails.
I => (org.http4s.Request[F], org.http4s.Response[F] => F[Either[E, O]])
toRequest(Endpoint, Option[String]): given the optional base URI, returns a function which generates a request and a response parser from endpoint inputs. Response parser returns an instance of
DecodeResultwhich contains the decoded response body or error details.
I => (org.http4s.Request[F], org.http4s.Response[F] => F[DecodeResult[Either[E, O]]])
Note that the returned functions have one-argument: the input values of end endpoint. This might be a single type, a tuple, or a case class, depending on the endpoint description.
After providing the input parameters, the following values are returned:
- An instance of
org.http4s.Request[F]with the input value encoded as appropriate request parameters: path, query, headers and body. The request can be further customised and sent using an http4s client, or run against
- A response parser to be applied to the response received after executing the request. The result will then contain the decoded error or success values (note that this can be the body enriched with data from headers/status code).
See the runnable example for example usage.
- Multipart requests are not supported yet.
- WebSockets are not supported yet.
- Streaming capabilities:
Fs2Streamsare supported at the moment.