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

Http4s EntityDecoder not being auto derived for simple case class

I am getting this error: Cannot decode into a value of type com.blah.rest.model.UserProfile, because no EntityDecoder[cats.effect.IO, com.blah.rest.model.UserProfile] instance could be found. for the following case class: case class…
iyerland
  • 632
  • 2
  • 10
  • 24
4
votes
1 answer

Scala HTTP4s print entire HTTP Error response

I wrote this code to use the http4s client library to make a POST call to a REST web service val client = SimpleHttp1Client() val form = UrlForm("username" -> userName, "password" -> password) val uri = Uri.fromString(url).valueOr(throw _) val list…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
3
votes
1 answer

How to get the full URL from an Http4s Request

I'm trying to obtain the beginning of the URL that a client used to access a webserver in Http4s. I.e. given a Request[F] I want to obtain the string "http://localhost:8080" or "https://my-app.company.com" depending on where the server is…
Dylan
  • 13,645
  • 3
  • 40
  • 67
3
votes
0 answers

Clarification around the concept of Path, Mount Point and Prefix in http4s

I'm trying to clarify some concept that confuse me slightly around http4s path. Quoting the documentation, Path info Path matching is done on the request’s pathInfo. Path info is the request’s URI’s path after the following: the mount point of the…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
3
votes
1 answer

How would you wrap a class containing a concurrenthash map with cats?

Say I have a class that contains an inner concurent hash map final class SomeClass() { private val byUserId = new ConcurrentHashMap[User.ID, Vector[User]](64) // ... } Now if I wanted to have this class referenced in my API endpoints and other…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
3
votes
1 answer

Is it possible to share pure FP state between multiple http requests on http4s server?

I'm trying to share state between multiple http requests on http4s server. That is what I tried: for { state <- Ref[F].of(0) _ <- BlazeServerBuilder[F] .bindHttp(port, host) .withHttpApp( ... httpApp that has link to…
Bogdan Vakulenko
  • 3,380
  • 1
  • 10
  • 25
3
votes
1 answer

How to convert into refined type?

I am using the library https://github.com/fthomas/refined and would like to convert java.util.UUID to refined's Uuid. How to convert java.util.UUID to refined's Uuid? Update I have the following http routes: private val httpRoutes: HttpRoutes[F] =…
softshipper
  • 32,463
  • 51
  • 192
  • 400
3
votes
1 answer

Cannot find an implicit value for ContextShift

I am trying to create webapp with http4s that is based on Http4sServlet. The following code does not compile: import cats.effect._ import org.http4s.servlet.BlockingServletIo import org.http4s.servlet.Http4sServlet import…
softshipper
  • 32,463
  • 51
  • 192
  • 400
3
votes
1 answer

Running http4s server with ZIO Env

Trying to learn using ZIO library, so I decided to create a basic web service app. Idea pretty basic, use http4s lib for server and route endpoints, print "hello world" on endpoint call. With the help of docs and examples I found, produces…
Bublik
  • 912
  • 5
  • 15
  • 30
3
votes
1 answer

How to combine AuthedRoutes and HttpRoutes in http4s?

Is there any rule how http4s prioritize AuthedRoutes over HttpRoutes when both of them are combined with <+> Because I receive 401 for such a combination authRoute <+> route, when calling: GET /non-authed-route The behavior changes, and I receive…
Alex Fruzenshtein
  • 2,846
  • 6
  • 32
  • 53
3
votes
1 answer

http4s Received premature EOF

I want to implement an http4s server that receives the content from another service, processes it and return the response. The original service uses redirects so I added the Follow redirect middleware. I also added the Logger middleware to check…
Labra
  • 1,412
  • 1
  • 13
  • 33
3
votes
1 answer

Integration tests for Http4s Client/Resource

I'm implementing a Vault client in Scala using Http4s client. And I'm now starting to write integration tests. So far I have this: abstract class Utils extends AsyncWordSpec with Matchers { implicit override def executionContext =…
Simão Martins
  • 1,210
  • 11
  • 22
3
votes
0 answers

How to use TSec (with http4s) for per resource authorisation

I'm currently setting up a new http4s server and looking into the authentication/authorisation mechanism and found TSec. After going through TSec's documentation and also this example code, I couldn't figure out a way to implement authorisation on a…
andrewscs
  • 31
  • 2
3
votes
1 answer

sbt shading two versions of a dependency

When I run my tests I see the following error: Exception: java.lang.NoSuchMethodError: fs2.Stream$.bracket(Ljava/lang/Object;Lscala/Function1;Lscala/Function1;)Lfs2/internal/FreeC; I first made sure my build file was cleaned up by explicitly…
codenoodle
  • 982
  • 6
  • 19
3
votes
1 answer

HTTP4S client. How to get the exact request and response body

I am writing a small http4s client val client = SimpleHttp1Client() val uri = Uri.fromString(requestUrl).valueOr(throw _) val task = POST(uri, UrlForm("username" -> userName, "password" -> password)).map{request => println("request: " +…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
1 2
3
10 11