I have a Akka source as a stream of numbers implemented as:
Source(Stream(1, 2, 3, 4, 5))
I am trying make use of Akka streaming support in Akka HTTP to return a streaming response as comma-separated values.
I have followed akka doc on simple csv source streaming to come up with the following implementation:
implicit val csvFormat = Marshaller.strict[Int, ByteString] { res =>
Marshalling.WithFixedContentType(ContentTypes.`text/csv(UTF-8)`, () => {
ByteString(List(res).mkString(","))
})
}
implicit val streamingSupport: CsvEntityStreamingSupport = EntityStreamingSupport.csv()
complete(Source(Stream(1, 2, 3, 4, 5)))
But apparently this is not the right use case of CSV entity streaming support for my purpose. This results in every number being streamed in a new line.
But that is not what I want. I want to reply as comma-separated list instead, like 1,2,3,4,5.
How is it possible to achieve this using streaming support in Akka HTTP?