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

Schema based ops for en- and decoding bodies #2569

Merged
merged 2 commits into from
Jan 7, 2024

Conversation

987Nabil
Copy link
Contributor

Currently, we leave transforming data from and to bodies more or less to the user.
We only understand basic types like String or Chunk[Byte].

But since we have the endpoint API and a strong relationship with zio-schema, I think it makes sense, to have schema based operators, that can create and decode bodies.

  • We don't need to add additional libs
  • It will ease the fallback to the low-level API, when the user fails to do their task with the Endpoint API

This implementation is agnostic of the encoding (not json specific) and just requires an implicit BinaryCodec.

@987Nabil 987Nabil force-pushed the schema-based-body-ops branch from 6b2f76e to ff1039f Compare December 26, 2023 15:46
@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f4b2b3f) 64.23% compared to head (ea9cc05) 64.24%.

Files Patch % Lines
zio-http/src/main/scala/zio/http/QueryParams.scala 50.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2569   +/-   ##
=======================================
  Coverage   64.23%   64.24%           
=======================================
  Files         140      140           
  Lines        8358     8357    -1     
  Branches     1604     1586   -18     
=======================================
  Hits         5369     5369           
+ Misses       2989     2988    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@987Nabil 987Nabil marked this pull request as ready for review December 26, 2023 15:59
* val decodedPerson = body.as[Person]
* }}}
*/
def as[A](implicit codec: BinaryCodec[A], trace: Trace): Task[A] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be to or into? as has a meaning in some ZIO contexts as map(_ => a).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the name because it is called queryAs if you want to get a typed query param

Copy link
Contributor Author

@987Nabil 987Nabil Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I am fine with both. I can change it next time a PC is in reach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that should be queryTo or queryInto for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it then also be body.toString and not body.asString? But this has an obvious conflict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, please update any other cases like this that you find.

* val body = Body.from(person)
* }}}
*/
def from[A](a: A)(implicit codec: BinaryCodec[A], trace: Trace): Body =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this is called from almost does imply to or into.

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge with a name change, including one to queryAs (queryTo / queryInto). Thanks for your work on this!

@987Nabil 987Nabil force-pushed the schema-based-body-ops branch from ff1039f to ea9cc05 Compare January 6, 2024 23:25
@987Nabil
Copy link
Contributor Author

987Nabil commented Jan 7, 2024

@jdegoes please take a look again. I changed too much to feel go to merge without an additional review

@jdegoes jdegoes merged commit 11f13c9 into zio:main Jan 7, 2024
14 checks passed
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

Successfully merging this pull request may close these issues.

3 participants