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
1 answer

fs2: Check for success of Seq(Task)

I have an asynchronous http4s client from which I get a collection of results, after running some requests. I want to check that this collection (a Seq[Task[Response]]) has finished for all Task objects, and that the Response objects are in a…
2
votes
1 answer

Encoding recursive data structure into Json with Circe when running on http4s

I am building a very simply service, that should return a tree like structure defined through a recursive case class: case class Node(id: Int, name: String, children: Seq[Node] = Seq()) But for some reason I keep getting a following compilation…
singleton
  • 326
  • 2
  • 13
2
votes
2 answers

Setting Cookies using Http4s Client

I am using Http4s library to make HTTP calls to a REST web service. the rest web service requires me to set an authentication cookie. I have written the following code to set this cookie. val client = PooledHttp1Client() val uri =…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
1
vote
0 answers

http4s-ember-server throws ClosedChannelException from time to time

Using http4s-ember-server on one of my applications I notice from time to time these exceptions appearing in my server's logs. What is odd about them is that they don't follow my logger's appender or formatting style, they are just plain text like…
Hunor Kovács
  • 1,062
  • 9
  • 16
1
vote
0 answers

How to log non fatal errors in the console while running a http4s server in Scala

I have been using http4s for a while now. However, every time I am handling runtime errors, my workflow is very slowed down due to, for example, when I make a request to an endpoint and something goes wrong (either the JSON in the body cannot be…
1
vote
0 answers

Returning user friendly error messages when the JSON value is incorrect?

Currently my API endpoint works fine in the happy path if the JSON value corresponds to my case class correctly. How can I return a user friendly message when it doesn't? case class UpdateUserRequest ( registrationStatus: String, level:…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1
vote
1 answer

Pattern type is incompatible with expected type?

I am trying to create a post endpoint for a particular route but am getting the error message Pattern type is incompatible with expected type found ContextRequest[F,A], required: Request[F] case _ @ POST -> Root / "batch-notify" as _ => …
1
vote
1 answer

http4s shutdown takes 30 seconds?

I'm learning http4s and trying out the basic example from the documentation, and I've noticed something weird. Simply starting and stopping the server works fine, but if any requests are sent, a graceful shutdown takes about 30 seconds (during which…
Modus Operandi
  • 552
  • 1
  • 6
  • 24
1
vote
1 answer

How to enable hostNameVerifier on server side in http4s BlazeServerBuilder

In one of my project we are moving away from akka (v10.2.9) to http4s (v0.23.12). In akka we are creating http server using akka.http.scaladsl.Http object which internally creates HttpConnectionContext for server using AkkaSSLConfig which by default…
tpsaitwal
  • 422
  • 1
  • 5
  • 23
1
vote
1 answer

How do you obey x-rate-limit headers using cats-effect and the http4s client?

As this should be purely functional I put together this limiter class (as of now it might contain bugs since I couldn't use it yet but you get the idea). But how do I actually use it? I went ahead and tried to write a client middleware as per…
TomPoczos
  • 95
  • 1
  • 9
1
vote
1 answer

How to retrieve error message in HTTP4S client?

I am trying to use Blaze client for http4s to make http calls. It works fine when 200 response is returned but in case of HTTP 500 or 400 I am not able to figure out how to retrieve the detailed error message returned from server. I am can only see…
Amit Kumar
  • 2,685
  • 2
  • 37
  • 72
1
vote
1 answer

How to create frontend project from multiple scala.js projects?

My project is a game server with frontend for it. For the frontend I'm using scala.js. Project is a cross-build so I can share files between jvm (server) and js (client). Cross-build method:…
Onajk
  • 21
  • 5
1
vote
0 answers

How to migrate akka http (using custom directives) to http4s

Let's say I define this route using Akka Http: POST method If there's a specific header in the request I will remove it but I will add a new header with the same value (it is like I'm replacing a header in the request). I'm using a custom directive…
M.G.
  • 369
  • 1
  • 14
1
vote
1 answer

Migrating from Akka Http to Http4s - custom directives

I'm starting to learn Http4s, at work we may need to migrate Rest APIs implemented with Akka Http to Http4s. As an example I can define a custom directive like this: trait CustomDirectives { def extractUUID: Directive1[UUID] = { …
M.G.
  • 369
  • 1
  • 14
1
vote
1 answer

Integration tests hangs when testing my API in ZIO + HTTP4S

I am having issues testing my first ZIO+HTTP4S application. The test hangs and does not finish. The code for my App (simplified) is object Main extends App { def server: ZIO[AppEnvironment, Throwable, Unit] = for { (...) fullApp…