Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respond in valid JSON Array when using streams #4116

Open
grzegorz-bielski opened this issue Oct 24, 2024 · 1 comment
Open

Respond in valid JSON Array when using streams #4116

grzegorz-bielski opened this issue Oct 24, 2024 · 1 comment

Comments

@grzegorz-bielski
Copy link

Hello!

In http4s there is streamJsonArrayEncoderOf which allows you to use fs2.Stream but encode it as a valid JSON Array.

When in one of our services we switched to Tapir for endpoints definitions, we noticed that this functionality is missing, or at the very least we are not sure how to achieve it.

For us, this is very useful, as for short streams, it allows for easier integration with different tools that might not understand NDJSON or other approaches.

As a workaround we roll out our own stream json array encoding, but It'd be nice to have this built-in in Tapir, maybe as an opt-in.

@adamw
Copy link
Member

adamw commented Oct 29, 2024

This is definitely doable (a matter or providing a way of translating a Stream[F, MyCaseClass] to Stream[F, Byte]), though it would need to reside in a fresh module depending on: circe, fs2 and tapir. A bit specialised ... but maybe worth it?

And I suppose the gist of the integration would be to copy this method: https://github.com/http4s/http4s/blob/50f988442c15193b3495ca695997c14a2dd778b6/circe/src/main/scala/org/http4s/circe/CirceInstances.scala#L291-L315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants