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

Friendlier Forms in ZIO HTTP #1953

Merged
merged 5 commits into from
Feb 19, 2023
Merged

Friendlier Forms in ZIO HTTP #1953

merged 5 commits into from
Feb 19, 2023

Conversation

scottweaver
Copy link
Contributor

@scottweaver scottweaver commented Jan 21, 2023

Friendly Forms MK II

This is pretty much complete rewrite of the previous Friendly Forms API that only initially supported 'application/x-www-form-urlencoded'.

User API: Form

'zio.http.forms.Form' provides the user the tools they need to:

  • Encode 'application/x-www-form-urlencoded' to a 'zio.http.Body'.
  • Decode a 'zio.http.Body' that is encoded as 'application/x-www-form-urlencoded' to a 'zio.http.forms.Form'.
  • Encode 'multipart/form-data ' to a 'zio.http.Body'.
  • Decode a 'zio.http.Body' that is encoded as 'multipart/form-data' to a 'zio.http.forms.Form'.

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2023

Codecov Report

Base: 62.16% // Head: 62.49% // Increases project coverage by +0.33% 🎉

Coverage data is based on head (4120fa6) compared to base (e8b7556).
Patch coverage: 72.36% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1953      +/-   ##
==========================================
+ Coverage   62.16%   62.49%   +0.33%     
==========================================
  Files         196      204       +8     
  Lines        5849     6045     +196     
  Branches      208      220      +12     
==========================================
+ Hits         3636     3778     +142     
- Misses       2213     2267      +54     
Impacted Files Coverage Δ
.../main/scala/zio/http/forms/FormDecodingError.scala 0.00% <0.00%> (ø)
...rc/main/scala/zio/http/netty/NettyBodyWriter.scala 37.50% <0.00%> (ø)
...o-http/src/main/scala/zio/http/netty/package.scala 100.00% <ø> (ø)
zio-http/src/main/scala/zio/http/Body.scala 77.04% <25.00%> (-8.14%) ⬇️
...scala/zio/http/forms/ContentTransferEncoding.scala 38.46% <38.46%> (ø)
...-http/src/main/scala/zio/http/forms/Boundary.scala 73.91% <73.91%> (ø)
zio-http/src/main/scala/zio/http/forms/Form.scala 75.36% <75.36%> (ø)
...-http/src/main/scala/zio/http/forms/FormData.scala 81.48% <81.48%> (ø)
...http/src/main/scala/zio/http/forms/FormState.scala 81.81% <81.81%> (ø)
...o-http/src/main/scala/zio/http/forms/FormAST.scala 86.66% <86.66%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

/**
* Represents a form that can be either multipart or url encoded.
*/
sealed trait Form { self =>
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps FormData instead of Form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my first preference, but there is already a FormData elsewhere in the codebase :(

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can consolidate?

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 am using now using FormData. However, I don't see a reasonable way to combine it as the other variant is only related to ContentDisposition.

@scottweaver
Copy link
Contributor Author

scottweaver commented Jan 23, 2023

While this initial implementation conveys what I feel the form API should look like from a usability perspective it ends up being too naive to support the more complex cases one might encounter when dealing multipart/formdata.

I will continue experimenting to come up with an implementation powerful enough for the multipart case yet remains simple and performant in the urlencoded case.

@jdegoes
Copy link
Member

jdegoes commented Feb 8, 2023

@scottweaver Please re-open when you're ready for another look!

@jdegoes jdegoes closed this Feb 8, 2023
@scottweaver
Copy link
Contributor Author

Pretty much a rewrite from the ground up that supports both application/x-www-form-urlencoded and multipart/form-data.

The only functionality remaining is support of 'multipart/mixed' for multipart forms.

scala-steward and others added 3 commits February 18, 2023 12:05
This is pretty much complete rewrite of the previous Friendly Forms API that only initially supported 'application/x-www-form-urlencoded'.

User API: Form
==============

'zio.http.forms.Form' provides the user the tools they need to:

- Encode 'application/x-www-form-urlencoded' to a 'zio.http.Body'.
- Decode a 'zio.http.Body' that is encoded as 'application/x-www-form-urlencoded' to a 'zio.http.forms.Form'.
- Encode 'multipart/form-data  ' to a 'zio.http.Body'.
- Decode a 'zio.http.Body' that is encoded as 'multipart/form-data' to a 'zio.http.forms.Form'.
@scottweaver scottweaver changed the title [WIP] Friendlier Forms in ZIO HTTP Friendlier Forms in ZIO HTTP Feb 18, 2023
@vigoo vigoo merged commit b2c84ec into main Feb 19, 2023
@vigoo vigoo deleted the friendly-forms.1 branch February 19, 2023 16:01
@vigoo vigoo mentioned this pull request Mar 1, 2023
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.

Multipart form data client support Multipart form data server support
5 participants