当前位置: 首页 > 知识库问答 >
问题:

带有表单和链接的JSON超媒体Api

齐向笛
2023-03-14
"links": [ 
{"rel": "self", "href":"http://example.org/entity/1"},
{"rel": "friends", "href":"http://example.org/entity/1/friends"}] 
"forms" : [
{"rel" : "new client", "action" : "/clients", "method": "post", 
"fields" : ["name":"string", "zipcode":"int", "signedup":"date", "state": ["Alabama",...]...]}]

顺便说一句,真的很好的谈话!

所有的输入都很感激!

共有1个答案

戎志勇
2023-03-14

我已经研究了这个主题一段时间,但我不确定ppl使用哪些可能的解决方案,哪些不使用。只有几个例子...所以我需要一些专家的审查...(我的示例将主要使用HAL+JSON。)

1.)

我有一种感觉,链接关系应该只得到,因为在HTML中,它们是用来包括样式表之类的东西的。我想其他ppl也有同样的感觉,因为IANA有一个edit-form和一个create-form链接关系。

{
    "_links": {
        "edit-form": {
            "href": "http://example.com/users/1?form=edit",
            "type": "text/html",
            "title": "Edit user"
        }
    }
}

>

  • 如果我们发送数据,那么我们可以使用类型来描述请求正文而不是响应正文。OFC.在这种情况下,不应该有一个响应机构,否则这个解决方案会令人困惑。

        {
            "_links": {
                "curies": [
                    {
                        "name": "my",
                        "href": "http://example.com/rels/{rel}",
                        "templated": true
                    }
                ],
                "my:edit": {
                    "href": "http://example.com/users/1",
                    "type": "application/vnd.example.user+json",
                    "title": "Edit user"
                }
            }
        }
    

    因此,在本例中,客户机将知道my:edit意味着这是一个编辑表单,并且通过检查MIME类型,它将知道要显示的表单类型。

    将自定义链接关系用于相同目的的替代解决方案:

        {
            "_links": {
                "curies": [
                    {
                        "name": "my",
                        "href": "http://example.com/rels/{rel}",
                        "templated": true
                    }
                ],
                "my:edit-user": {
                    "href": "http://example.com/users/1",
                    "type": "application/json",
                    "title": "Edit user"
                }
            }
        }
    
        {
            "_links": {
                "curies": [
                    {
                        "name": "my",
                        "href": "http://example.com/rels/{rel}",
                        "templated": true
                    }
                ],
                "my:edit": {
                    "href": "http://example.com/users/1",
                    "type": "application/json",
                    "title": "Edit user",
                    "profile": "http://example.com/profiles/user"
                }
            }
        }
    

    >

  • 例如,dougrain-forms这样做:

        {
            "_forms": {
                "edit": {
                    "href": "http://example.com/users/1",
                    "headers": {
                        "content-type": "application/json"
                    },
                    "title": "Edit user",
                    "method": "PUT",
                    "schema": {
                        "required": [
                            "name"
                        ],
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string"
                            }
                        },
                        "title": "user properties"
                    }
                }
            }
        }
    

    但是,只要我们没有关于HAL和HAL表单的标准,您可以使用任何替代方法,例如,我宁愿使用类似于猫鼬模式的解决方案:

        {
            "name": "John",
            "_links": {
                "curies": [
                    {
                        "name": "my",
                        "href": "http://example.com/rels/{rel}",
                        "templated": true
                    }
                ],
                "my:edit": {
                    "href": "http://example.com/users/1",
                    "type": "application/json",
                    "title": "Edit user",
                    "method": "PUT",
                    "_embedded": {
                        "schema": {
                            "name": "String"
                        }
                    }
                }
            }
        }
    

    4.)

    {
        "@context": [
            "http://www.w3.org/ns/hydra/core",
            "https://example.com/docs#"
        ],
        "@id": "https://example.com/users/1",
        "name": "John",
        "operation": {
            "@type": "ReplaceResourceOperation",
            "title": "Edit user",
            "method": "PUT",
            "expects": {
                "@id": "https://example.com/docs#User",
                "supportedProperty": {
                    "@type": "SupportedProperty",
                    "title": "name",
                    "property": "https://example.com/docs#User.name",
                    "range": "http://www.w3.org/2001/XMLSchema#string",
                    "required": true
                }
            }
        }
    }
    

  •  类似资料:
    • 问题内容: 对于不可编辑的UITextView,我想在iOS9 +中嵌入这样的文本: 只需单击此处进行注册 我可以创建一个函数并处理文本,但是有没有更简单的方法? 我看到我可以使用NSTextCheckingTypeLink,因此在Interface Builder中无需“ click here”部分就可以单击文本: 只需http://example.com进行注册 如果相关,我正在使用Xcode

    • 我现在正在读《实践中的Rest》一书。我无法理解以下术语超媒体,超媒体格式,超媒体控件,域应用协议。作者建议需要特定领域的超媒体格式。我很难理解这些。我在谷歌上搜索了这些术语,但没有找到正确的答案。谁能解释一下这些术语,以及为什么我们需要特定于领域的超媒体格式而不是应用程序/XML?

    • 我有一个带有ui路由器的AngularJS应用程序,它使用带有超媒体的REST API。一般的想法是让API为其各种调用生成URL,并防止客户机自己构造URL。 还有别的想法吗? 除非我在这方面非常错误,否则我不是在寻找模板化的解决方案,即API返回一个url模板的解决方案,该url模板需要客户机注入参数。关键在于url已经填充了数据,因为有些url比上面提供的示例要复杂得多。

    • JavaFX是否提供类似Eclipse Quickfix的东西?这意味着您将鼠标悬停在损坏的东西上,并为其找到了一些可以立即应用的解决方案。我知道有工具提示,但它们只能包含文本,我需要一些可点击的东西。另一种解决方案是类似对话框的东西,但我不想打开另一个窗口。我希望它出现在当前阶段。有什么建议吗? 编辑:为了说明这一点,我想在基于JavaFX的应用程序上采用eclipse快速修复的概念,当鼠标悬停