Skip to content

Support form creation #447

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

Closed
wants to merge 65 commits into from
Closed

Conversation

gillarramendi
Copy link

We have been reviewing the state of the art regarding HATEOAS within Java environments such as Spring HATEOAS and JAX-RS and none of the implementations include any form (create/update) support, only link creation.

Taking into account that the most important hypermedia format (HTML) includes a great support for forms, offering a complete and self-contained description of the update/create options offered by a web app, we consider that it would be an interesting feature to add this support to Spring HATEOAS.
It means that clients will know which is the contract offered by the API update/create interactions, including the possible fields and if necessary the possible values for each property/field. In other words, the hypermedia format will guide the developer to implement form interactions with a self-contained format.

Of course, the first decision to add this support is to define the hypermedia format. There are already some hypermedia formats that support forms, like Hydra and Siren. We consider that the most natural option that fits with Spring HATEOAS, based on HAL, is HAL-FORM (https://github.com/mamund/hal-forms). Basically, an optional extension of HAL for forms support.

As an starting point, we created a first draft implementation including a form builder that allows the definition of the form fields and a *_MessageConverter *_that renders it in HAL-FORM format. In addition, we have proposed some updates within HAL-FORM specification, basically to determine the possible values for each field, and we are in conversations with Mike Amundsen @mamund, the specification author, to include them in the specification.

We created an example application that shows the usage of the new API to create Forms (https://github.com/hdiv/hal-forms-sample).

For example, a form with two fields is created in this way:

ControllerFormBuilder formBuilder = ControllerFormBuilder
    .formTo(ControllerFormBuilder.methodOn(TaskController.class).create(new Task()));

formBuilder.property("description").readonly(false);
formBuilder.property("priority").suggest().values(new Priority[]{Priority.High, Priority.Low});
Form form = formBuilder.withDefaultKey();

resource.add(form);

And the generated HAL-FORMS response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/tasks"
    }
  },
  "_templates": {
    "default": {
      "method": "POST",
      "properties": [
        {
          "name": "description",
          "readOnly": false
        },
        {
          "name": "priority",
          "suggest": {
            "values": [
                "HIGH",
                "MEDIUM",
                "LOW"
              ]
          }
        }
      ]
    }
  }
}

Any thoughts will be appreciated.
Thanks in advance.

@robertovelasco, @iunanua, @gillarramendi

igor and others added 30 commits April 14, 2016 13:45
…d use HalResourcesSerializer for serializing _embedded
gregturn added a commit that referenced this pull request May 12, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334,
gregturn added a commit that referenced this pull request May 12, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 12, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 13, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 13, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 13, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 13, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 17, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 18, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 20, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request May 20, 2017
* Adds new Affordances API
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on marked up domain objects and controllers
Attempted rebase of review/affordances against master

Original pull-request: #340, #447
Related issues: #503, #334
gregturn added a commit that referenced this pull request Jul 28, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334
gregturn added a commit that referenced this pull request Jul 28, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334
gregturn added a commit that referenced this pull request Aug 11, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334
gregturn added a commit that referenced this pull request Aug 14, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-Forms, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334
gregturn added a commit that referenced this pull request Aug 15, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334

Polish
gregturn added a commit that referenced this pull request Aug 15, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334
gregturn added a commit that referenced this pull request Aug 15, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334, #71
gregturn added a commit that referenced this pull request Nov 6, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334, #71
gregturn added a commit that referenced this pull request Nov 27, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334, #71
odrotbohm pushed a commit that referenced this pull request Nov 29, 2017
* Introduces new Affordances API to build links related to each other to serve other mediatypes
* Introduces HAL-FORMS, which uses affordances to automatically generate HTML form data based on Spring MVC annotations.

Original pull-request: #340, #447, #581
Related issues: #503, #334, #71
@gregturn
Copy link
Contributor

Superceded by #612 and resolved via 70448a8.

Final solution isn't precisely the same thing, but we plan to iterate over it in the near future and expand to support other mediatypes. Feel free to check the HAL-FORMS section of code and their corresponding unit tests.

Also, see monitor Spring HATEOAS Examples repo as we plan to add an Affordances example very soon.

@gregturn gregturn closed this Nov 29, 2017
@pivotal-issuemaster
Copy link

@gillarramendi Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

1 similar comment
@pivotal-issuemaster
Copy link

@gillarramendi Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@gillarramendi Thank you for signing the Contributor License Agreement!

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.

6 participants