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

Add json body to http4s Request

This tut shows how to create an http4s Request: https://http4s.org/v0.18/dsl/#testing-the-service I would like to change this request to a POST method and add a literal json body using circe. I tried the following code: val body =…
Herman J. Radtke III
  • 1,804
  • 1
  • 24
  • 29
11
votes
3 answers

http4s - get request body as String or InputStream

I'm trying to define HttpService that receives json and parses it to case class with json4s library: import org.http4s._ import org.http4s.dsl._ import org.json4s._ import org.json4s.native.JsonMethods._ case class Request(firstName: String,…
mixel
  • 25,177
  • 13
  • 126
  • 165
10
votes
2 answers

How to log all requests for an http4s client

I want to log all the requests my application makes. The application makes several call like this: val client: Client = org.http4s.client.blaze.SimpleHttp1Client(...) client.fetch(Request(method = GET, uri = aUri)) Is there a way of getting the…
Paul McKenzie
  • 19,646
  • 25
  • 76
  • 120
9
votes
3 answers

Generate Swagger / OpenAPI specification from scala source code (http4s)

So I'm no swagger expert, but all systems using swagger require you to have the swagger specification in JSON or YAML defining all endpoints (and such) of your API. My question is: Are there know ways to generate these specification files based on…
Tom Lous
  • 2,819
  • 2
  • 25
  • 46
7
votes
0 answers

Unit Testing http4s router websocket endpoints

The idea is to be able to unit test websocket endpoints on a router service. Any other kind of endpoint is fairly easy to test with a Request, but I can't figure out a way of easily testing websocket responses, as hitting the endpoint with a Request…
smetca
  • 71
  • 4
7
votes
1 answer

How to gracefully shutdown http4s

I'm using http4s BlazeServer 0.21, how can I graceful shutdown? I want to reject all upcoming requests, and keep process unfinished requests and response back, within a hard shutdown time. I tried starting server with serveWhile and set a…
ong
  • 96
  • 5
7
votes
1 answer

How to increase request timeout for http4s

I have a request that is talking to a backend db that takes time to respond. And the http4s is throwing request timeout. I wanted to know if there is a property to increase the request timeout? Thanks Saad.
saad
  • 371
  • 3
  • 13
7
votes
1 answer

Circe Encoders and Decoders with Http4s

I am trying to use http4s, circe and http4s-circe. Below I am trying to use the auto derivation feature of circe. import org.http4s.client.blaze.SimpleHttp1Client import org.http4s.Status.ResponseClass.Successful import io.circe.syntax._ import…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
6
votes
2 answers

http4s - how create blaze client with limited count of threads?

I trying to create blaze client with limited number of threads like this: object ReactiveCats extends IOApp { private val PORT = 8083 private val DELAY_SERVICE_URL = "http://localhost:8080" // trying create client with limited number of…
vaan
  • 350
  • 1
  • 8
  • 21
6
votes
2 answers

How to add custom error responses in Http4s?

Whenever I hit unknown route in my http4s application it returns 404 error page with Content-Type: text/plain and body: Not found How can I force it to always return body as JSON with Content-Type: application/json? {"message": "Not found"} I…
Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
6
votes
1 answer

Cannot find an implicit value for ContextShift[cats.effect.IO] in http4s version 19.0.0

I have a http4s project which uses ciris for configuration management. The project is in github here. libraryDependencies ++= Seq( "is.cir" %% "ciris-cats", "is.cir" %% "ciris-cats-effect", "is.cir" %% "ciris-core", "is.cir" %%…
user51
  • 8,843
  • 21
  • 79
  • 158
6
votes
1 answer

How to shutdown a fs2.StreamApp programmatically?

Extending StreamApp asks you to provide the stream def. It has a requestShutdown parameter. def stream(args: List[String], requestShutdown: F[Unit]): Stream[F, ExitCode] I provide the implementation for this and understand that args is passed in as…
Toby
  • 9,523
  • 8
  • 36
  • 59
5
votes
1 answer

How do I verbalize the term F[_] in scala/cats-effect

I'm learning the concept of F[_] as a constructor for other types, but how do you pronounce this to another human or say it in your head (for us internal monologue thinkers). Similar to how x => x + 1 has an official verbalization of "x goes to x…
WhiteleyJ
  • 1,393
  • 1
  • 22
  • 29
5
votes
1 answer

Http4s Client Encode Entity as x-www-form-urlencoded Recursively

I have a request like the following val request = Request[IO]( method = POST, uri = Uri.uri("..."), headers = Headers( Authorization(BasicCredentials("...", "...")) ) ) …
sinanspd
  • 2,589
  • 3
  • 19
  • 37
5
votes
1 answer

org.http4s.client Post with header and UriForm

With using org.http4s.client can't find how I can send headers and UriForm together with Post request. import org.http4s.client.dsl.io._ import org.http4s.Method._ val lstHeader: List[Header] = List( Header("Accept", "application/json") ,…
Aleksey N Yakushev
  • 443
  • 1
  • 3
  • 11
1
2 3
10 11