Packages

package playjson

Type Members

  1. trait JsonEntitiesFromCodecs extends algebra.JsonEntitiesFromCodecs

    Partial interpreter for endpoints.algebra.JsonEntitiesFromCodecs that only fixes the JsonCodec[A] type to Play’s Format[A].

    Partial interpreter for endpoints.algebra.JsonEntitiesFromCodecs that only fixes the JsonCodec[A] type to Play’s Format[A].

    The jsonRequest and jsonResponse 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"))
      )
    
    }

Interpreters