package playjson
Type Members
- trait JsonEntitiesFromCodecs extends algebra.JsonEntitiesFromCodecs
Partial interpreter for endpoints4s.algebra.JsonEntitiesFromCodecs that only fixes the
JsonCodec[A]
type to Play’sFormat[A]
.Partial interpreter for endpoints4s.algebra.JsonEntitiesFromCodecs that only fixes the
JsonCodec[A]
type to Play’sFormat[A]
.The
jsonRequest
andjsonResponse
operations have to be implemented by a more specialized interpreter.Typical usage:
/* shared MyDto.scala */ case class MyDto(i: Int, s: String) object MyDto { import play.api.libs.{Format, Json} implicit val jsonFormat: Format[MyDto] = Json.format[MyDto] }
/* shared endpoint definition */ trait MyEndpoints extends algebra.Endpoints with algebra.playjson.JsonEntitiesFromCodec { val myEndpoint = endpoint(get(path), jsonResponse[MyDto]) }
/* client MyEndpointsClient.scala */ object MyEndpointsClient extends MyEndpoints with xhr.JsonEntitiesFromCodec with xhr.faithful.Endpoints MyEndpointsClient.myEndpoint().map(myDto => println(myDto.i))
/* server MyEndpointsServer.scala */ object MyEndpointsServer extends MyEndpoints with play.server.JsonEntitiesFromCodec { val routes = routesFromEndpoints( myEndpoint.implementedBy(_ => MyDto(42, "foo")) ) }