简体   繁体   中英

Structuring dynamic form data served from an API

Im looking into serving, what essentially is, dynamic forms on the client side (and especially validation rules for the form fields) from an open API. I have limited experience of this area and when i looked it seemed that different clientside validation frameworks for example tend to be similar, but not identical, on the client-side (whereas jquery validate is among the largest).

From an API perspective i feel it is logical in some sense not to become opinionated in regards to what validation framework the consumer uses (if possible). But at the same time i feel it does not feel right rolling your own if established practises on how the structure should look already exists.

I should mention that i know many recommend serving for example validation rules through OPTIONS Verb. But my issue is not where, rather the format of the output.

So what i wondered is: Are there any open / established / de-facto standards in regards to structuring form and validation data being served in json format from an API? Or is it all normally opinion-based and home-rolled (or structured for a specific validation framework)?

The closest i have been able to find is http://json-schema.org .

UPDATE: I think i can answer my own question in regards to this after having plowed through the area a bit more. There are no unified standards in regards to the actual data, it depends on needs and wishes.

What DO have standard specs are different HATEOAS formats (which encapsulates the data and adds relationship information between resources). Then Json Schema provides the schema details of the request objects themselves, making it possible to for example validate the json request / response objects (which might, or might not, coincide with form validation-rule requirements).

There seems to be a multitude of client-side validation framework where some uses json schema and some other formats. But in the end it is a matter of design choises.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM