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

Better WWW form data support #477

Merged
merged 4 commits into from
Dec 8, 2024
Merged

Better WWW form data support #477

merged 4 commits into from
Dec 8, 2024

Conversation

Blacksmoke16
Copy link
Member

@Blacksmoke16 Blacksmoke16 commented Dec 8, 2024

Context

#426 refactored how query parameters are resolved for a controller action, it only handles one-off params. You might notice yourself adding the same parameters to your actions over and over. This PR expands on the last one by introducing a new ATHA::MapQueryString annotation which works similarly to ATHA::MapRequestBody, but for the query string of a request.

This effectively allows you to use the same DTO pattern for query params as you can request bodies. This PR also allows resolving WWW form data into a DTO as well via URI::Params::Serializable.

Changelog

  • Add ATHA::MapQueryString to map a request's query string into a DTO type
  • Support deserializing application/x-www-form-urlencoded bodies via ATHA::MapRequestBody
  • Add ATH::Request#content_type_format to return the request format's name from content-type header

Before merging, remember to add the athena-framework/athena prefix to the PR number in the PR title

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Flag Coverage Δ
compiled 8.15% <0.00%> (-0.02%) ⬇️
unit 92.71% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
clock 98.18% <ø> (ø)
console 92.61% <ø> (ø)
dependency_injection 64.28% <ø> (ø)
dotenv 96.80% <ø> (ø)
event_dispatcher 82.75% <ø> (ø)
framework 94.01% <100.00%> (+0.05%) ⬆️
image_size 95.03% <ø> (ø)
mercure 93.37% <ø> (ø)
negotiation 97.69% <ø> (ø)
routing 92.96% <ø> (ø)
serializer 87.23% <ø> (ø)
spec 93.54% <ø> (ø)
validator 92.37% <ø> (ø)

📢 Thoughts on this report? Let us know!

rescue ex : JSON::ParseException | ASR::Exception::DeserializationException
raise ATH::Exception::BadRequest.new "Malformed JSON payload.", cause: ex
rescue ex : URI::SerializableError
raise ATH::Exception::BadRequest.new "Malformed www form data payload.", cause: ex
Copy link
Member Author

Choose a reason for hiding this comment

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

This and the other are technically wrong as this error is only raised when the underlying data is missing a required property. But I'm going to leave it and just address this more holistically as part of #290.

@Blacksmoke16 Blacksmoke16 marked this pull request as ready for review December 8, 2024 04:52
@Blacksmoke16 Blacksmoke16 merged commit 0a0f769 into master Dec 8, 2024
14 checks passed
@Blacksmoke16 Blacksmoke16 deleted the map-query-string branch December 8, 2024 15:09
PallasAthenaie pushed a commit to athena-framework/framework that referenced this pull request Dec 8, 2024
* Leverage `URI::Params::Serializable` to handle form data request body resolution
* Add `ATHA::MapQueryString` to map a request's query string into a DTO type
* Add `ATH::Request#content_type_format` to return the request format's name from `content-type` header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant