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

Add a contentType property to the HAL-FORMS template element automatically or by hand #1087

Open
ingogriebsch opened this issue Sep 24, 2019 · 9 comments

Comments

@ingogriebsch
Copy link

ingogriebsch commented Sep 24, 2019

@gregturn asked me on Gitter to create this issue.

We talked about how one could add a 'contentType' property to a HAL-FORMS template element, either automagically or by hand.

@ingogriebsch Trying to understand HAL-FORMS in more detail and currently wondering how I can control to add a 'contentType' to a 'template'.

@gregturn And we haven't (yet) coded support to populate the rest of the HAL-FORMS fields. Spring HATEAOS has sought to capture a vendor neutral format that can be serialized into multiple media types. That avoids having to bake media type awareness into your application. However, when it comes to media type specifics, we may need to consider adding, perhaps, annotations to fill in the bits like contentType. For example, would a @HalForms annotation be useful on a domain object to flesh those details out? Is that the best approach?

@ingogriebsch I expected that the Introspection mechanism checks if the @RequestMapping on the @RestController has defined a 'consumes' or 'produces' and adds a 'contentType' element to the input and/or output without any further ado. I also checked the Affordances API if it allows me to define a contentType through the PayloadMetadata. Another option would be some kind of additional information on the object which represents the payload (maybe through a @HalForms as you mentioned) but it could be hard to add an annotation on every type of payload one wants to use (how about a MultipartFile for example?).

@gregturn That's a good idea. If you captured the consumes/produces idea into an issue, we can pursue that.

Feel free to change/cleanup this ticket as you wish. If I can help in some way, please let me know! :)

Original discussion starts here: https://gitter.im/spring-projects/spring-hateoas?at=5d876bbac77f285fb1c25f86

@odrotbohm
Copy link
Member

I am torn on this one as the spec currently defines only application/json and application/x-www-form-urlencoded as supported media types, there's little value in exposing the contentType property as application/json is the only value that makes sense for now.

Does it make sense to ask @mamund to open up that clause, so that e.g. custom media type declarations could be used at least?

@gregturn
Copy link
Contributor

Given the encType for an HTML5 <form> is not confined to these two types, I agree that widening the HAL-FORMS spec to allow other media types should be possible.

@mamund
Copy link

mamund commented Oct 31, 2019 via email

@gregturn
Copy link
Contributor

gregturn commented Oct 31, 2019

Thanks @mamund! I opened mamund/hal-forms#30 to track this in the spec.

@mamund
Copy link

mamund commented Oct 31, 2019 via email

gregturn added a commit that referenced this issue Nov 1, 2019
Adds the ability to specify input media types and output media types in the AffordanceBuilder APIs. This is, in turn, used by SpringAffordanceBuilder and applying the `consumes` and `produces` clauses for Spring MVC/WebFlux's annotations. HAL-FORMS in turn can populate `contentType` using this information. Other media types are free to leverage this additional information as well.
gregturn added a commit that referenced this issue Nov 1, 2019
Adds the ability to specify input media types and output media types in the AffordanceBuilder APIs. This is, in turn, used by SpringAffordanceBuilder and applying the `consumes` and `produces` clauses for Spring MVC/WebFlux's annotations. HAL-FORMS in turn can populate `contentType` using this information. Other media types are free to leverage this additional information as well.
gregturn added a commit that referenced this issue Nov 1, 2019
Adds the ability to specify input media types and output media types in the AffordanceBuilder APIs. This is, in turn, used by SpringAffordanceBuilder and applying the `consumes` and `produces` clauses for Spring MVC/WebFlux's annotations. HAL-FORMS in turn can populate `contentType` using this information. Other media types are free to leverage this additional information as well.
gregturn added a commit that referenced this issue Nov 1, 2019
Adds the ability to specify input media types and output media types in the AffordanceBuilder APIs. This is, in turn, used by SpringAffordanceBuilder and applying the `consumes` and `produces` clauses for Spring MVC/WebFlux's annotations. HAL-FORMS in turn can populate `contentType` using this information. Other media types are free to leverage this additional information as well.
@gregturn
Copy link
Contributor

gregturn commented Nov 1, 2019

I've coded a patch that adds incoming and outgoing media types to the AffordanceModelFactory and AffordanceBuilder API. SpringAffordanceBuilder is able to use this to collection consumes/produces details from Spring MVC/WebFlux methods and embed them in the affordance details.

HAL-FORMS can now look up incoming media types and use it to populate contentType. Other media types are free to leverage this additional meta data.

The changes are as backwards compatible as possible, with deprecations in place, which we should be able to then remove in the 1.2 time frame.

The test controller have been updated to demonstrate this, but it's debatable if we want to keep those changes. We may wish to have a separate WebFluxEmployeeController/WebMvcEmployeeController that exercises and verifies this feature.

Feedback welcome.

@gregturn
Copy link
Contributor

gregturn commented Nov 1, 2019

@odrotbohm WDYT?

@ingogriebsch
Copy link
Author

@gregturn I like it! 👍

@gregturn
Copy link
Contributor

gregturn commented Feb 6, 2020

@odrotbohm the HAL-FORMS spec has been expanded such that other media types may be plugged into the contentType field. I'll check the status of the branch involving this work and see if it can't be cleaned up and reviewed.

gregturn added a commit that referenced this issue Feb 6, 2020
Adds the ability to specify input media types and output media types in the AffordanceBuilder APIs. This is, in turn, used by SpringAffordanceBuilder and applying the `consumes` and `produces` clauses for Spring MVC/WebFlux's annotations. HAL-FORMS in turn can populate `contentType` using this information. Other media types are free to leverage this additional information as well.
@gregturn gregturn added this to the 1.2.0-M1 milestone Apr 30, 2020
@odrotbohm odrotbohm modified the milestones: 1.2 M1, 1.2 RC1 Aug 11, 2020
@gregturn gregturn modified the milestones: 1.2 RC1, 1.2 GA Sep 15, 2020
@odrotbohm odrotbohm modified the milestones: 1.2 GA, 1.3 M1 Oct 27, 2020
@odrotbohm odrotbohm modified the milestones: 1.3 M1, 1.3 M2 Jan 13, 2021
@odrotbohm odrotbohm modified the milestones: 1.3 M2, 1.3 RC1 Feb 16, 2021
@odrotbohm odrotbohm modified the milestones: 1.3 M3, 1.4 M1 Mar 15, 2021
@odrotbohm odrotbohm modified the milestones: 1.4 M1, 1.4 M2 Jul 14, 2021
@odrotbohm odrotbohm modified the milestones: 1.4 M2, 1.4 M3 Aug 12, 2021
@odrotbohm odrotbohm modified the milestones: 1.4 M3, 1.4 candidates Sep 16, 2021
@odrotbohm odrotbohm removed this from the 1.4 candidates milestone Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants