I've got an end point that I wish could provide either JSON or HTML version of the same data, depending on how the client's
Accept header prefers.
This should be easy with akka-http (2.4.10) Marshalling support, but I don't get it to work.
val genHtml = () => HttpEntity( ContentTypes.`text/html(UTF-8)`, s"<!DOCTYPE html><html><p style:\"color:$color\">$color</p></html> " )
val genJson = () => JsObject( "color" -> JsString(color.s))
Marshall.oneOf method is the one I should use, but how? I haven't found an actual sample online, yet. There's
In the one-off case, I just pass a
JsObject and the spray-akka-http bridging has a
ToResponseMarshaller for it.