'How to generate form and crud using Spring and React

I want to dynamically generate crud form based on my API.

I am using spring, spring-data-rest and spring-hateoas.

I don't wan't to render react from java.

I was thinking of tweaking /profile and add some meta informations for rendering my form.

Does anyone has an implementation recommandations for me ?

I have seens that some react projects that is similar with what I require client side, but it is not adapted for spring:

https://github.com/mozilla-services/react-jsonschema-form



Solution 1:[1]

Spring Data Rest can return ALPS or JSON Schema, just change the Accept header:

Accept: application/schema+json
GET http://example.com/profile/foos

So, if you have an entity like:

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class Foo {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String owner;

    private String name;
}

You will get a response like:

{
  "title": "Foo",
  "properties": {
    "owner": {
      "title": "Owner",
      "readOnly": false,
      "type": "string"
    },
    "name": {
      "title": "Name",
      "readOnly": false,
      "type": "string"
    }
  },
  "definitions": {},
  "type": "object",
  "$schema": "http://json-schema.org/draft-04/schema#"
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Neil McGuigan