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
2
votes
0 answers

Retrieve query parameter with RFC3986 reserved characters not decoded in Tapir/http4s

I'm new to Scala (and thus tapir/http4s) and I would like to get a query parameter with RFC 3986 reserved characters not percent-decoded. Indeed, I'm using some reserved characters as delimiters (namely , and :) but when…
FredericS
  • 413
  • 4
  • 9
2
votes
1 answer

http4s json handling in authed routes

I am using Scala 3 and http4s 1.0.0-M35. I want to use auth with json handling. val routes = AuthedRoutes.of[User, IO] { case request@POST -> Root / "dialog" / LongVar(dialogId) / "send" as user => { for { sendMessageRequest <-…
LIshy2
  • 150
  • 6
2
votes
1 answer

Scala, http4s, fs2. Why does fileupload using http4s with fs2 reads just one line while reading as bytes reads completely

I have the following snippet using multi part file uploads. One of the parts reads as byte while the other reads string. One that reads as Byte shows the correct size while the one reading as String reads only one line. What am I missing ? val…
nashter
  • 1,181
  • 1
  • 15
  • 33
2
votes
0 answers

Upgrading http4s from 0.21.0-M6 to 0.21.33

I had some waitQueue size limit exceeded issues in the past with my http4s-blaze-client@0.21.0-M6. As per the recommendation I am trying to upgrade my http4s version from 0.21.0-M6 to 0.21.33. Now I am facing the below compilation error in the…
Madhu Reddy
  • 53
  • 1
  • 8
2
votes
0 answers

Is there a shutdown hook for http4s / blaze / cats-effect

I am running a http4s server using a blaze backend with cats-effect IO effects. I have an event logger that collects events and periodically flushes them to persistent storage. I'm wanting to ensure that any events in the queue are flushed before…
Joseph Thomas-Kerr
  • 339
  • 1
  • 4
  • 14
2
votes
1 answer

How to create an endpoint with Tapir in Scala with multiple Schemas

I’m just heading an issue when I’m trying to create an endpoint with multiple bodies shape. My model looks like this: sealed trait FileExampleTrait { def kind: String } case class FileExampleOne(name: String, length: Int) extends FileExampleTrait…
2
votes
1 answer

Http4s Blaze Client Builder wait queue full failure

We have a use case where for a single incoming request, a microservice has to make many(nearly 1000 in worst case) outgoing HTTP calls to other microservice to fetch GET some details. Our service is built using Scala, Http4s and Cats-Effect and is…
Madhu Reddy
  • 53
  • 1
  • 8
2
votes
1 answer

MongoDriver for Scala + http4s : How to check if createCollection() throws an exception?

I'm a Scala - http4s beginner. I have to create a MVC application for my job using Scala with http4s and I'm facing the following problem : I can't catch mongo driver exceptions inside Repository One of my tasks is to create new databases for some…
2
votes
1 answer

What is the name of the design pattern for marshalling in libraries like Akka Http or http4s?

In libraries like akka-http or http4s there is always a pattern where you define objects doing the marshalling from/to JSON. When you later need to use the serialization you import the implicits so they are used in function methods. For a project…
tonicebrian
  • 4,715
  • 5
  • 41
  • 65
2
votes
1 answer

http4s Received premature EOF error for 2 per of request

we are doing performance testing for our application. we are getting org.http4s.InvalidBodyException: Received premature EOF error. The problem is we are getting only for 1-2 per of requests. The percentage will increase if we will increase rps. The…
Vimit Dhawan
  • 597
  • 1
  • 7
  • 25
2
votes
1 answer

Decode an optional query parameter using QueryParamDecoder in Scala

I want to decode an optional query parameter in my Scala code. I'm using http4s. The parameter is of the form ?part=35/43. End goal is to store this fraction as a Type Part = (Int, Int) so that we can have (35, 43) as a tuple to use further in the…
fan
  • 23
  • 4
2
votes
0 answers

How to stream fs2.Queue without items loosing in case of client disconnect

I need to stream fs2.Queue - some events to single http client. import cats.effect._ import org.http4s._ import org.http4s.dsl.io._ import org.http4s.server.Router import org.http4s.server.blaze.BlazeServerBuilder import…
zella
  • 4,645
  • 6
  • 35
  • 60
2
votes
1 answer

How to compose two Http4s routes with zio effect and different types of environment

I have two Http4s routes: val routes1:HttpRoutes[Task] = ??? val routes2:HttpRoutes[RTask] = ??? Where RTask is just a Task/RIO with a custom environment: type RTask[A] = RIO[Env,A] Composing of two routes with the same type parameters can be…
Bogdan Vakulenko
  • 3,380
  • 1
  • 10
  • 25
2
votes
1 answer

Http4s decoder how to customize error message for invalid fields

I have following code like: case req @ POST -> Root => req .decode[UserCreateRequest] { decodedRequest => my stack is http4s + zio. Ive added custom decoder for this case class where I have a line: email <-…
FrancMo
  • 2,459
  • 2
  • 19
  • 39
2
votes
1 answer

Correct way to deal with a case of POST method request Http4s

I have a Post request sent over a network to get data related to a user I'm using Http4s for this. When writing the HttpRoutes I'm using this to handle the case of POST as follows: case req @ POST -> Root/ "posts" { "name": username, "friends":…
A M
  • 23
  • 6