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

A simple way to iterate over paginated reponse Http4s

I'm trying to handle pagination without using string interpolation and also take advantage of http4s features. I have came across the OptionalQueryParamDecoderMatcherand I don't know if it is a good match in my use case. So the response contain…
Mar Es
  • 33
  • 4
2
votes
2 answers

Converting an `Option[A]` to an Ok() or NotFound() inside an Http4s API

I've got an API that looks like this: object Comics { ... def impl[F[_]: Applicative]: Comics[F] = new Comics[F] { def getAuthor(slug: Authors.Slug): F[Option[Authors.Author]] = ... and a routing that looks like this: object Routes…
sshine
  • 15,635
  • 1
  • 41
  • 66
2
votes
1 answer

Log url of request on InternalServerError in http4s

http4s returns InternalServerError if an unhandled error happened. Is it possible to log url of the request when InternalServerError happened? If yes, what is the best way to do it?
sergeda
  • 2,061
  • 3
  • 20
  • 43
2
votes
1 answer

How do I convert a java.util.UUID to doobie.syntax.SqlInterpolator.SingleFragment?

I am trying to set up a simple scala app with database using doobie, http4s and circe. How do I convert a java.util.UUID to doobie.syntax.SqlInterpolator.SingleFragment ? final case class User(id: UUID, details: UserDetails) implicit val…
Ry2254
  • 859
  • 1
  • 10
  • 19
2
votes
1 answer

How to deploying Scala HTTP4S app to Heroku?

I am trying to deploy a Scala HTTP4S app to Heroku. sbt -sbt-version 1.3.12 new http4s/http4s.g8 -b 0.21 Used the above command to get the giter8 template from HTTP4S. herokuAppName in Compile :=…
Ry2254
  • 859
  • 1
  • 10
  • 19
2
votes
1 answer

Shadow/Remove string interpolator

I'm using two libraries which define string interpolators (simplified code for clarity): Http4s: implicit class LiteralsOps(val sc: StringContext) extends AnyVal { def uri(args: Any*): Uri = macro LiteralSyntaxMacros.uriInterpolator (...) def…
Simão Martins
  • 1,210
  • 11
  • 22
2
votes
1 answer

decoder for refined type when using circe with Http4s

I am trying to use refined types for a case class but couldn't figure out how the encoder will actually work. For json parsing circe is used with https4s library. type AgeT = Int Refined Interval.ClosedOpen[0,100] type NameT = String Refined…
Abhi
  • 130
  • 11
2
votes
0 answers

no context on this server matched or handled this request

I have built a web app with http4s that uses Jetty as Servlet container. The code below shows the implementation of the server: @WebListener class Bootstrap extends ServletContextListener with IOApp { override def contextInitialized(sce:…
softshipper
  • 32,463
  • 51
  • 192
  • 400
2
votes
0 answers

How to secure http4s webapp with keycloak?

I would like to secure my Http4s based webapp with Keycloak, which is described on https://www.keycloak.org/docs/latest/securing_apps/index.html#_jetty9_adapter. The http4s webapp runs on Jetty as you can see on the code snippet object…
softshipper
  • 32,463
  • 51
  • 192
  • 400
2
votes
1 answer

Change from http to https using http4s

Is there any way to change a http server to https using the library http4s? (https://http4s.org/)
2
votes
0 answers

Getting 403 forbidden error in Get request using http4s

I am doing a short assignment in http4s and I am getting 403 error from a long time which is difficult to debug. My code is: object Assignment extends App { implicit val cs: ContextShift[IO] = IO.contextShift(global) implicit val timer:…
2
votes
1 answer

Scala, Circe, Http4s - is it any way to encode Throwable in Circe?

I have created hierarchy of errors: sealed trait MyError extends Throwable final case class SecondError(msg: String) extends MyError Now I could get this kind of error in my http4s routes: case GET -> Root / "things" => for { response <-…
Developus
  • 1,400
  • 2
  • 14
  • 50
2
votes
0 answers

Stub a Http4s 0.20.x Client for testing

I'd like to test that a Http4s Client is being called from my class ClassUnderTest (to make a HTTP request) and that the request made contains the headers I expect. In 0.18.x, I did something like below. Using a side effect to store the value of the…
Toby
  • 9,523
  • 8
  • 36
  • 59
2
votes
1 answer

http4s: What is difference between actual and expected value?

versions: http4s: 0.18.1 specs2: 4.0.0 I'm using http4s and writing unit test for routers, but there are little documents about headers assertion. When code below is executed, it can be compiled, but fails. code: import cats.effect.IO import…
ryochanuedasan
  • 528
  • 1
  • 6
  • 11
2
votes
1 answer

Open Websocket connection using http4s

I'm running http4s WS example from: https://github.com/http4s/http4s/blob/master/examples/blaze/src/main/scala/com/example/http4s/blaze/BlazeWebSocketExample.scala And I'm trying to connect to it from google chrome console: var ws = new…
Nikita
  • 4,435
  • 3
  • 24
  • 44