Skip to content

Streaming CSV back to API client #37750

Answered by mschorsch
dodalovicgran asked this question in Q&A
Discussion options

You must be logged in to vote

I have not tested it, but something like that should do the trick:

import io.smallrye.mutiny.coroutines.awaitSuspending
import io.vertx.mutiny.pgclient.PgPool
import io.vertx.mutiny.sqlclient.*
import jakarta.enterprise.context.ApplicationScoped
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow

@Path("/fruits")
@ApplicationScoped
class FruitsResource(
    private val pgPool: PgPool
) {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    fun getFruits(): Flow<String> {
        return flow { getFruits() }
    }…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@geoand
Comment options

geoand Dec 15, 2023
Collaborator

@mschorsch
Comment options

Comment options

You must be logged in to vote
3 replies
@mschorsch
Comment options

@geoand
Comment options

geoand Dec 16, 2023
Collaborator

@mschorsch
Comment options

Comment options

You must be logged in to vote
2 replies
@mschorsch
Comment options

@dodalovicgran
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by dodalovicgran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants