Provides EntityEncoder
and EntityDecoder
support for play-json JSON library.
libraryDependencies += "org.http4s" %% "http4s-play-json" % "0.23.13"
import org.http4s.play._
import play.api.libs.json._
// Lets fetch some JSON from a website and parse it
// into a case class that has a play-json `Format` defined (Reads/Writes)
// Assumes that https://mydomain.invalid/sample.json responds:
// { "hello": "world" }
case class SampleResponse(hello: String)
object SampleResponse {
// Play-json formatter for { "hello": "world" }
implicit val format: Format[SampleResponse] = Json.format
}
// Fetch with an http4s client
val client: Client[F] = ???
val target = Uri.uri("http://mydomain.invalid/sample.json")
// The response will be deserialised to a `SampleResponse`
// using the implicit play-json `Format`
val response: F[Sample] = httpClient.expect[SampleResponse](target)
The Typelevel Discord has an #http4s channel. Please join us!
Other JSON compatibility modules for http4s include: http4s-circe (in the core repo) and http4s-fabric.