How to add resource and specify related element?

☆樱花仙子☆ 提交于 2019-12-11 13:57:57

问题


I have a simple API for a game tip website:

  • /class is the endpoint for in game classes
  • /tip is the endpoints for the tips
  • /user is the endpoint for the users

Each tip has 3 relations:

  • (:User)-[:AUTHORED]-(:Tip)
  • (:Class)<-[:FOR]-(:Tip)
  • (:Class)<-[:AGAINST]-(:Tip)

When I create a Tip using POST, I do'nt know how to add relations at the create time.

I can do this way: Add relation to another node in SDN4 + REST after creating the resource, but I want to do it with only one query.

EDIT: I tried to POST this:

'{"content":"TEST", "forClass":"/class/2", "againstClass":"/class/2"}'

and the item has been created, no InvalidArgument Exception raised, but if I go to my class resource's tips, I don't have any tips:

GET /class/2/tips:

{
  "_embedded" : {
    "tip" : [ ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/class/2/tips"
    }
  }
}

GET /tip/9 (the created one):

{
  "content" : "TEST",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/tip/9"
    },
    "tip" : {
      "href" : "http://localhost:8080/tip/9"
    },
    "author" : {
      "href" : "http://localhost:8080/tip/9/author"
    },
    "againstClass" : {
      "href" : "http://localhost:8080/tip/9/againstClass"
    },
    "forClass" : {
      "href" : "http://localhost:8080/tip/9/forClass"
    }
  }
}

GET /tip/9/forClass:

{
  "name" : null,
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/class/2"
    },
    "bnSClass" : {
      "href" : "http://localhost:8080/class/2"
    },
    "tips" : {
      "href" : "http://localhost:8080/class/2/tips"
    }
  }
}

来源:https://stackoverflow.com/questions/35412463/how-to-add-resource-and-specify-related-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!