简体   繁体   English

构建从API提供的动态表单数据

[英]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. 我正在研究从开放的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). 我在这方面的经验有限,当我看时,似乎不同的客户端验证框架例如在客户端上往往是相似但不相同的(而jquery validate是其中最大的)。

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). 从API的角度来看,我认为从某种意义上说,不要对消费者使用哪种验证框架(如果可能的话)持怀疑态度是合乎逻辑的。 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. 我应该提到,我知道许多建议通过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? 所以我想知道的是: 关于从API以json格式提供的表单和验证数据的结构化,是否有任何公开/既定/事实上的标准? 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 . 我能找到的最接近的是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). 具有标准规范的是不同的HATEOAS格式(封装数据并添加资源之间的关系信息)。 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). 然后,Json Schema提供请求对象本身的模式详细信息,从而可以验证json请求/响应对象(可能或可能不符合表单验证规则要求)。

There seems to be a multitude of client-side validation framework where some uses json schema and some other formats. 似乎有许多客户端验证框架,其中一些使用json模式,而另一些使用其他格式。 But in the end it is a matter of design choises. 但最终这是设计选择的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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