Questions tagged [http4s]

Http4s is a minimal, idiomatic Scala interface for HTTP services.

http4s is a typeful, purely functional HTTP library for client and server applications written in Scala.

Principles

Typeful: http4s uses Scala’s type system to increase self-documentation and compile-time verification. Standard headers are lazily parsed to semantically meaningful types, and typeclasses are provided to encode and decode bodies to several common formats.

Purely functional: The pure functional side of Scala is favored to promote composability and easy reasoning about your code. The core is built on an immutable case class model of HTTP requests and responses, shared by the client and the server.

Asynchronous: Much of the API is built around a scalaz.concurrent.Task. Bodies are modeled as scalaz-streams for performant chunking of large messages in constant memory.

Modular: http4s has a lightweight core with multiple deployment options. Server applications can be deployed to blaze, the native platform, or as a servlet application. Client applications run on either blaze or an async-http-client backend. Several libraries useful in everyday HTTP programming, such as circe and argonaut, are integrated via optional modules.

Community-oriented: http4s is a community-driven project, and aims to provide a welcoming environment for all users. We are proud to be a Typelevel incubator project.

Official website: http://http4s.org/

161 questions
1
vote
1 answer

why is there a type parameter IO in Request as in http4s Request[IO]?

There's a type parameter IO in Request as in http4s Request[IO]. Why is it necessary, what do we have as an effect here, when is this effect executed?
Son
  • 877
  • 1
  • 12
  • 22
1
vote
1 answer

Scala 3 + http4s problem with encode/decode json

I have a Scala 3 project (3.0.0 version) and I'm trying to build simple Rest API with http4s. I have a problem with decoding/encoding JSON. I'm building my code based on http4s.g8. The issue occurs on this line: implicit val jokeDecoder:…
martyn
  • 136
  • 1
  • 8
1
vote
0 answers

Access logging for scala application on http4s

We have a rest microservice developed using scala http4s. For logging we are using logback.xml. We want to configure 'access logs', similar to how we have it for…
1
vote
1 answer

How to compose an effect with an Http4s HttpRoutes?

I have an http4s HttpRoutes and a task in my effect type (ZIO, if that matters). The effect is side-effecting and returns no value. I want to compose the two together, creating a new HttpRoutes that will run the effect before any matching route in…
wingedsubmariner
  • 13,350
  • 1
  • 27
  • 52
1
vote
1 answer

Compose stream of effects for http response

I want to make a streaming JSON response via HTTP. The purpose is to send current time in a given city every second. TL;DR: I need help with sending a result in effect F and a function, which returns this effect, should be called every 1 second. Is…
George Zorikov
  • 139
  • 1
  • 4
  • 8
1
vote
1 answer

Http4s circe can not decode children

I have error model like: sealed trait HttpError { val msg: String val cause: String } final case class HttpDecodingError(cause: String) extends HttpError { override val msg: String = "Decoding error" } final case class…
FrancMo
  • 2,459
  • 2
  • 19
  • 39
1
vote
1 answer

ZIO 1.0.3 changes the way environments work and now http4s Blaze won't run

I'm using ZIO for the first time and I started with a boilerplate stub from https://github.com/guizmaii/scala-tapir-http4s-zio/blob/master/src/main/scala/example/HttpApp.scala that uses ZIO version 1.0.0-RC17 to set up and run an http4s Blaze…
emote_control
  • 745
  • 6
  • 21
1
vote
1 answer

http4s route matching for GET requests with params on root host

I have simple rout-mapping function which using http4s: import cats.syntax.all._ import org.http4s._ import org.http4s.circe._ def routeMapper: PartialFunction[Request[F], F[Response[F]]] = { case r @ POST -> Root => create case r @ PUT -> Root…
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28
1
vote
1 answer

How to define an http4s server as a ZIO ZLayer to be injected and fetched in the main?

Help me define an http4s using ZLayers. I'm learning and I'm confused. I'd like to factor out the http server as a component. But I don't know how to compose the ZManageds and the the ZLayers so that it would compile. Also does it makes sense to…
Hunor Kovács
  • 1,062
  • 9
  • 16
1
vote
2 answers

Compilation problem between HttpRoutes[RIO[E, *]] and HttpRoutes[zio.Task]

Trying to compile this small ZIO friendly Tapir/Http4s Endpoint description import io.circe.generic.auto._ import org.http4s.HttpRoutes import sttp.tapir.json.circe import sttp.tapir.ztapir._ import sttp.tapir.server.http4s.ztapir._ import…
arinray
  • 178
  • 1
  • 12
1
vote
1 answer

make Rho swagger.json not requier Auth

Faced a problem while trying to implement self-documenting API using Rho lib (https://github.com/http4s/rho) By requirements our Routes should be protected by Auth middleware (https://http4s.org/v0.21/auth/) and now swagger.json generated by Rho…
user2997302
  • 115
  • 2
  • 10
1
vote
0 answers

Custom prometheus metrics in http4s

In http4s docs there is an example of adding /metrics endpoint to the routes provided by Http4s: https://http4s.org/v0.21/middleware/ All of them are predefined by the library, but I was wondering if there is a possibility of adding custom metrics,…
fr3ak
  • 493
  • 3
  • 16
1
vote
2 answers

http4s decompress gzipped http response

I try decompress gzipped simple response on client side. What the appropriate way to do it with http4s? import cats.effect.{Blocker, ContextShift, IO, Timer} import java.util.concurrent._ import org.http4s.{Header, Headers, HttpVersion, Method,…
Aleksey N Yakushev
  • 443
  • 1
  • 3
  • 11
1
vote
1 answer

Get cookies in middleware in http4s?

I'm trying to write middleware that would extract specific cookie and store information in ContextRequest. Here is my test code: def cookie[F[_]: Sync]( logger: Logger[F] ): Kleisli[F, Request[F], ContextRequest[F, Option[Cookie]]]…
sergeda
  • 2,061
  • 3
  • 20
  • 43
1
vote
1 answer

FS2: How to get a java.io.InputStream from a fs2.Stream?

Say I have val fs2Stream: Stream[IO, Byte] and I need to, for example, call some Java library that requires a java.io.InputStream. I suppose that I'm way too new to FS2, but I cannot seem to find the answer. I've tried to use fs2.io.toInputStream…
foxtrotuniform6969
  • 3,527
  • 7
  • 28
  • 54