zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
800 stars 403 forks source link

Default encoding of `Enpoint.outStream[X]` should be JSON array, or the Content Type should be `application/json-seq` #3113

Closed gregor-rayman closed 1 month ago

gregor-rayman commented 2 months ago

Is your feature request related to a problem? Please describe. Conceptually when an endpoint returns a list of X, it is the same as when it returns a ZStream[, , X]. Currently the default output encoding for .out[X] is an JSON array. For .outStream[X] it is however a not separated collection of JSONs. The Content-Type in the response is application/json, correct one would be application/json-seq.

Describe the solution you'd like Either the data should be returned as a JSON array, so prefixed with [, separated by , and terminated by ], or the Content-Type should be application/json-seq. I'd prefer the array, because that makes the change change from .out[List[X]] to .outStream[X] an internal change of the server, without the need to change the clients.

Describe alternatives you've considered A viable solution currently (RC10) is to provide custom codes for endpoints with .outStream[X] stream outputs.

jdegoes commented 2 months ago

/bounty $125 to make .outStream[X] return a JSON array, and a test case to prove it.

algora-pbc[bot] commented 2 months ago

💎 $125 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #3113 with your implementation plan
  2. Submit work: Create a pull request including /claim #3113 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bounty • Share on socials

Attempt Started (GMT+0) Solution
🟢 @gregor-rayman Sep 10, 2024, 11:46:36 AM #3122
gregor-rayman commented 2 months ago

/attempt #3113

Implement an encoder with the data interspersed with [, ,, ]

For the decoder parse the array incrementally, not as a single JSON array

algora-pbc[bot] commented 2 months ago

💡 @gregor-rayman submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] commented 1 month ago

@gregor-rayman: You've been awarded a $125 bounty by ZIO! 👉 Complete your Algora onboarding to collect the bounty.

algora-pbc[bot] commented 1 month ago

🎉🎈 @gregor-rayman has been awarded $125! 🎈🎊