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

Unreachable Code warning in http4s route pattern matching

I have this simple Route defined with http4s: def routes: HttpRoutes[UserTask] = HttpRoutes.of[UserTask] { case GET -> Root / IntVar(id) => ... // returns a specific user case GET -> Root => // this line gives the warning …
pme
  • 14,156
  • 3
  • 52
  • 95
1
vote
0 answers

How to get value out of Response?

I would like to test my service, that have the following implementation: val health: HttpRoutes[IO] = HttpRoutes.of[IO] { case GET -> Root / "health" => Ok(Stream .awakeEvery[IO](1.second) .flatMap { _ => …
softshipper
  • 32,463
  • 51
  • 192
  • 400
1
vote
1 answer

How use guave cache loader in F polymorphic code

I have a service, that returns joke from official example: final case class JokeError(e: Throwable) extends RuntimeException def impl[F[_] : Sync](C: Client[F]): Jokes[F] = new Jokes[F] { val dsl = new Http4sClientDsl[F] {} import…
zella
  • 4,645
  • 6
  • 35
  • 60
1
vote
1 answer

Scala cats - problem with encoding/decoding jsons

I have created a simple routes: class MyRoutes[F[_] : Async](service: MyService[F]) extends Http4sDsl[F] { def routes: HttpRoutes[F] = HttpRoutes.of[F] { case req@PUT -> Root / "bets" => for { bet <- req.as[Bet] created…
Developus
  • 1,400
  • 2
  • 14
  • 50
1
vote
0 answers

http4s client returns partial payload

I'm using the AsyncHttpClient in http4s-0.19.0-M2 to make a client-call: for { resp <- http.expectOr[String](GET(url)){ error => error.as[String].map(body => throw new Exception(...) } _ <-…
shj
  • 1,558
  • 17
  • 23
1
vote
1 answer

Are non-stream WebSockets in Scala possible at all? Doesn't seem like it

In JavaScript and Python, two other languages I use a lot at work, it is very easy to set up a WebSocket server (or client) and send/receive messages. For example, check out this copied code from the js WS repo. It takes just this code to set up a…
CubemonkeyNYC
  • 273
  • 3
  • 17
1
vote
1 answer

WebSocket challenges with Scala and fs2/cats

I'm using Http4s to mount a websocket service that I can use to communicate between this backend service and a UI (piping status updates and completion % for a batch job). I'm using the BlazeBuilder Websocket Example to set up the service. The…
CubemonkeyNYC
  • 273
  • 3
  • 17
1
vote
2 answers

Can http4s do different status codes given a Future?

I'm using http4s, and I have a Try that generates some json data for a response: case GET -> Root / "something" => getSomethingTry() match { case Success(something) => Ok(something) case Failure(CustomNotFoundException(reason)) =>…
Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
1
vote
1 answer

How to parallelize a REST API crawler in http4s & fs2?

I wrote a sequential REST API crawler in http4s & fs2 here: https://gist.github.com/NicolasRouquette/656ed7a2d6984ce0995fd78a3aec2566 This is to query a REST API service to get a starting set of IDs, fetch elements for a batch of IDs and continue…
1
vote
1 answer

Communicate between http4s backend and Binding.scala frontend

I'm trying to use Binding.scala with an existing http4s backend service, but kind of lost on how they would fit together. I'm not sure how to "bind" a say fs2 Task or cats-effect IO with Binding.scala.
Zizheng Tai
  • 6,170
  • 28
  • 79
1
vote
1 answer

http4s client create Uri from a string

I wrote the following code using http4s client library import org.http4s.UrlForm import org.http4s.Uri import org.http4s.client.blaze.SimpleHttp1Client import org.http4s.dsl._ import org.http4s.client._ val requestUrl = s"$url/foo/bar" val client =…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
1
vote
1 answer

Camel password being partially logged after sanitization

This question is a follow on from : Camel http4 and url-encoded passwords being interpreted as separate arguments and is somewhat related to this update put in as part of Camel 2.14.x and 2.15.x for sanitizing password information... We're using…
Gary O' Donoghue
  • 362
  • 2
  • 4
  • 15
1
vote
0 answers

Is there a way to stream data received from an http endpoint directly into kafka using http4s?

http4s uses scalaz streams and there is scalaz streams implementation for kafka. Can we directly stream data received at an http endpoint into kafka like, http endpoint being the source and kafka being sink.…
Bharath
  • 9
  • 1
1
vote
1 answer

Very simple call cannot be made using http4s

I wrote this simple scala code using http4s library import org.http4s.client.blaze._ object ScalaHttpTest extends App { val c = PooledHttp1Client() val rTask = c.expect[String]("""http://localhost:50070/webhdfs/v1/user/?op=LISTSTATUS""") val…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
0
votes
0 answers

error:0A00010B:SSL while trying to connect local websocket server

I run a very basic websocket server. Just a copy-paste from https://http4s.org/v1/docs/service.html#running-your-service-as-an-app I tried to connect with the websocket server using Postman, curl, wscat... but everything give the same result. I will…
LancerX
  • 1,211
  • 7
  • 23
  • 40