带HYDRA的JSON-LD:如何定义自定义操作并指定其URL?

时间:2016-12-13 16:21:32

标签: rest json-ld hydra-core

我在somebasell / 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"}
}

1 个答案:

答案 0 :(得分:0)

  

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

     

{

     

“@上下文中,”: “https://contexts.dictionary.mycompany-group.com/person.jsonld”,

     

“@ ID”: “https://myapi.mycompany.com/persons/BE14A7269802498F992813885546D058”   ,     “@type”: “https://schema.org/Person”,     “名字”:“穆斯特曼”,     “操作”:[         {“@ type”:“DeleteResourceOperation”,“method”:“DELETE”},         {“@ type”:“ReplaceResourceOperation”,“method”:“PUT”}         ],

     

//现在如何使用HYDRA增强的JSON-LD指定这个?

您需要从节点引用其他“some_special_operation” 在上面或使用该操作创建一个新的顶级节点

  

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

     

URL:“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