Nodes Resource REST API - lrcry/ExpertMind GitHub Wiki
Nodes Resource REST API
Contents
Introduction
Nodes are created to represents indicators of identifying an expert in some fields.
A typical node looks like the following:
{
"nodeDisplay": "name",
"nodeDescription": "description",
"nodeTags": [
{ "_id": "someId" },
{ "_id": "otherId" }
],
"nodeParents": [
{ "_id": "aParent" }
],
"nodeChildren": [
{ "_id": "child1" },
{ "_id": "child2" }
],
"nodeVotes": [
{
"user_id": "someUser",
"node_id": "0d62543e9c20e1e7",
"type": "1"
}
],
"nodeStatus": "1",
"userId": "someUserId",
"nodeCreateAt": "2015-09-29 13:42:51",
"_id": "0d62543e9c20e1e7"
}
For a Node object, there are two permitted vote types:
"1" for voting up
"-1" for voting down
You can also give a user ID when creating a new root node or a child node. If there is no user ID given, the "userId" in Node object will be "Anonymous" (default value)
Nodes retrieval operations
Get a Node by ID
GET /api/nodes/{node_id}
The response will look like
{
"data": {
"nodeDisplay": "name",
"nodeDescription": "description",
"nodeTags": [
{ "_id": "someId" },
{ "_id": "otherId" }
],
"nodeParents": [
{ "_id": "aParent" }
],
"nodeChildren": [
{ "_id": "child1" },
{ "_id": "child2" }
],
"nodeVotes": [
{
"user_id": "someUser",
"node_id": "0d62543e9c20e1e7",
"type": "1"
}
],
"nodeStatus": "1",
"userId": "someUserId",
"nodeCreateAt": "2015-09-29 13:42:51",
"_id": "0d62543e9c20e1e7"
},
"success": "true"
}
If an ID is given but does not exist in database, an error will be returned as a response:
{
"data": "No node found with _id = 9292939i",
"success": "true"
}
Get all Nodes
GET /api/nodes
Get information of descendant nodes of a Node by its ID
GET /api/nodes/[node_id]/descendant
If a node is successfully retrieved, the response will generally be
{
"result": "success",
"data":
{
"nodeDisplay": "name",
"nodeDescription": "description",
"nodeTags": [
{ "_id": "someId" },
{ "_id": "otherId" }
],
"nodeParents": [
{ "_id": "aParent" }
],
"nodeChildren": [
{ "_id": "child1" },
{ "_id": "child2" }
],
"nodeVotes": [
{ "_id": "goodVote3329" },
{ "_id": "badVote10641" }
],
"nodeStatus": "1",
"nodeCreateAt": "2015-09-29 13:42:51"
}
}
Note: in this case the response will contain a list of descendant node information.
Get information of children nodes of a Node by its ID
GET /api/nodes/[node_id]/children/
Response:
{
"result": "success",
"data":
{
"nodeDisplay": "name",
"nodeDescription": "description",
"nodeTags": [
{ "_id": "someId" },
{ "_id": "otherId" }
],
"nodeParents": [
{ "_id": "aParent" }
],
"nodeChildren": [
{ "_id": "child1" },
{ "_id": "child2" }
],
"nodeVotes": [
{ "_id": "goodVote3329" },
{ "_id": "badVote10641" }
],
"nodeStatus": "1",
"nodeCreateAt": "2015-09-29 13:42:51"
}
}
Note: in this case the response will contain a list of children nodes information.
Nodes modification operations
Create a new node
POST /api/nodes
The API accept a request body in JSON as follows:
{
"nodeDisplay": "This is a test Node name",
"nodeDescription": "This is a test Node description",
"userId": "user_test_id"
}
If someone do this without logged in, just leave 'userId' as blank.
If the create successful, a JSON array of all nodes will be returned as a response.
Add a child node
POST /api/nodes
The request body will look like the following:
{
"nodeDisplay": "this is a test child node name",
"nodeDescription": "this is a test child node description",
"nodeParents": [
{"_id": "someParentId"}
],
"userId": "user_test_id"
}
Note: the difference between create a new node and add a child node to an existing node is the "nodeParents" in request body. If there is a parent node, then the request will lead to a new child node, otherwise a new root node.