【问题标题】:JSON-LD with HYDRA: how to define a custom operation and specify its URL?带有 HYDRA 的 JSON-LD:如何定义自定义操作并指定其 URL?
【发布时间】:2017-04-28 19:00:39
【问题描述】:

我有一个可以在 somebaseurl/myresource/id123 下访问的资源 该资源当然有一些属性,一些到其他资源的链接,但它也有一些支持的操作。 到目前为止,一切都很好。 只要这些操作对应于在 somebaseurl/myresource/id123 的资源的 url 上执行的 http 动词,一切正常。 但是,如果我定义了一些特殊操作,可以通过在 somebaseurl/myresource/id123/somespecialaction 上发布 POST 来访问? 我如何在资源中表示这一点? JSON-LD+Hydra 不支持操作,hydra 支持操作,但我无法为资源中的操作指定“端点”或“URL”属性。 所以我仅限于 somebaseurl/myresource/id123 可访问的操作(所有 HTTP 动词,仅此而已) 如何在资源表示中保留这些边界?

{
  "@context":"https://contexts.dictionary.mycompany-group.com/person.jsonld",
  "@id":"https://myapi.mycompany.com/persons/BE14A7269802498F992813885546D058",
  "@type":"https://schema.org/Person",
  "name": "Mustermann",
  "operation"
    : [
      {"@type": "DeleteResourceOperation","method": "DELETE"},
      {"@type": "ReplaceResourceOperation","method": "PUT"}
      ],
    // now how would one specify this with JSON-LD augmented by HYDRA?

    {"@type": "some_special_operation","method": "POST", URL:"https://myapi.mycompany.com/persons/BE14A7269802498F992813885546D058/some_special_operation"}
}

【问题讨论】:

    标签: rest json-ld hydra-core


    【解决方案1】:

    我正在寻找一种方法来指定对特定资源的操作 实例:操作的 URL 和 HTTP 方法应该是可指定的。 示例(请检查最后 3 行):

    {

    "@context":"https://contexts.dictionary.mycompany-group.com/person.jsonld",

    "@id":"https://myapi.mycompany.com/persons/BE14A7269802498F992813885546D058" , "@type":"https://schema.org/Person", “名称”:“Mustermann”, “手术”: [ {"@type": "DeleteResourceOperation","method": "DELETE"}, {"@type": "ReplaceResourceOperation","method": "PUT"} ],

    // 现在如何使用由 HYDRA 增强的 JSON-LD 来指定这一点?

    您需要从节点中引用另一个“some_special_operation” 以上或使用该操作创建一个新的顶级节点

    { "@type": "some_special_operation", “方法”:“POST”,

    网址:"https://myapi.mycompany.com/persons/BE14A7269802498F992813885546D058/so me_special_operation" } }

    所以

      BE14A7269802498F992813885546D058
        - operation: delete + put
    
      5546D058/some_special_operation
        - operation: post
    

      BE14A7269802498F992813885546D058
        - operation: delete + put
        - relationshipProperty:
          ... 5546D058/some_special_operation
             - operation: post
    

    您可以在其中为“relationshipProperty”选择一些属性,该属性描述 两种资源之间的关系。

    话虽如此,我们目前正在尝试简化这一点,请参阅https://github.com/HydraCG/Specifications/issues/3

    【讨论】:

    • 谢谢 - 由于 stack* 社区正在评估我的初学者级别,我无法投票赞成您的问题 ;))
    猜你喜欢
    • 1970-01-01
    • 2019-10-22
    • 2011-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 2014-12-17
    相关资源
    最近更新 更多