Skip to content
eces edited this page Jan 19, 2013 · 5 revisions

JavaScript API 라이브러리에서 내부적으로 이용하는 API이다.

사용자는 graph.set을 통해 다음과 같은 요청을 보내지만

graph.set({
	"user": 1003,
	"do": "like",
	"post": 1570
});

실제 쿼리는 controllers.Graph.addEdge를 통해

{
	"sId": 1003,
	"sType": "user",
	"v": "like",
	"oId": 1570,
	"oType": "post"
}

와 같은 요청을 받아 각각의 포인트를 models.Point.findById로 확인 후 넣게된다.

API Server Protocols

URL

모든 API앞에는 버전을 붙힌다. 예) mintpresso.com/api/v1/accounts

Authentication

지원 안함

Methods

  • GET: url에 데이터를 넣어 보낸다.
    • /v1/account/1/point?type=user&identifier=eces@mstock.org
    • 데이터가 없으면 404 Not Found
  • POST:
    • body의 content-type이 올바르지 않으면 400 Bad Request
    • body에 데이터(JSON)가 없으면 400 Bad Request
  • PUT:
  • DELETE:

Content-type

POST와 PUT의 경우에 반드시 콘텐츠 타입을 text/json 또는 application/json으로 보내야한다.

Response

모든 응답에는 아래와 같이 codemessage가 들어있다.

{
	"status": {
		"code": "200",
		"message": ""
	}
}
{
    "status": {
        "code": 404,
        "message": "Account(id=1) not found"
    }
}

Adding new account

URL: POST /v1/account

URI Parameters: email, name, password send via URL.

#####Examples:

{
    "status": {
        "code": 201,
        "message": ""
    },
    "account": {
        "id": 1,
        "email": "eces@mstock.org",
        "name": "Jin"
    }
}

#####Exceptions:

{
    "status": {
        "code": 400,
        "message": "Duplicated email"
    }
}

Find an account

URL: GET /v1/account/:accountId

#####Examples:

{
    "status": {
        "code": 200,
        "message": ""
    },
    "account": {
        "id": 1,
        "email": "eces@mstock.org",
        "name": "Jin"
    }
}

#####Exceptions:

{
    "status": {
        "code": 404,
        "message": "Account(id=0) not found"
    }
}

Adding new point

POST /v1/point

JSON Parameters:

{
  "point": {
    "type": String,
    "identifier": Optional - String,
    "data": Optional - JSON Object
  }
}

#####Examples:

{
  "point": {
    "type": ...,
    "identifier": "eces@mstock.org",
    "data": {
      "plan": "startup"
    }
  }
}
{
    "status": {
        "code": 201,
        "message": "Point created"
    },
    "point": {
        "id": 1,
        "type": "user",
        "identifier": "eces@mstock.org",
        "data": {
            "plan": "startup"
        },
        "_url": "http://localhost:9001/v1/account/1/point/1"
    }
}

#####Exceptions:

{
    "status": {
        "code": 200,
        "message": "Already defined."
    },
    "point": {
        "id": 1,
        "type": "user",
        "identifier": "eces@mstock.org",
        "data": {
            "plan": "startup"
        },
        "_url": "http://localhost:9001/v1/account/1/point/1"
    }
}

Getting one point

URL: GET /v1/accounts/:accountId/point/:pointId

URL: GET /v1/accounts/:accountId/user-:id

{
    "status": {
        "code": 200,
        "message": ""
    },
    "point": {
        "id": 1,
        "type": "user",
        "identifier": "eces@mstock.org",
        "createdAt": 1358231682597,
        "updatedAt": 1358231682597,
        "referencedAt": 1358231682597,
        "data": {
            "plan": "startup"
        },
        "_url": "http://localhost:9001/v1/account/1/point/1"
    }
}

Getting points

URL: GET /v1/accounts/:accountId/points

URL: GET /v1/accounts/:accountId/points/user

URL: GET /v1/accounts/:accountId/user-?

URI Parameters: type, identifier, limit, offset

typeidentifier중 하나를 지정하여 여러개의 모델을 가져올 수 있다.

_url
_prev
_next

Adding one or many edge

URL: POST /v1/accounts/:accountId/edge

{
	"edge": {
		"sId": Number,
		"v": String,
		"oId": Number
	}
}

Finding relationship

Connected points(adjancent vertice)를 찾는다.

URL: GET /v1/accounts/:accountId/relationship

? Applicable Urls:

  • GET /v1/accounts/:accountId/:objectType/:verb
  • GET /v1/accounts/:accountId/:objectId/:verb
  • GET /v1/accounts/:accountId/:objectType-:objectId/:verb
  • GET /v1/accounts/:accountId/:objectType/:verb/:subjectType
  • GET /v1/accounts/:accountId/:objectType/:verb/:subjectId
  • GET /v1/accounts/:accountId/:objectType/:verb/:subjectId

Don't be get panic.

JSON Parameters:

{
	"edge": {
		"sId": Number | -1
		"sType": String | "?"
		"v": String | "?"
		"oId": String | "?"
		"oType": Number | -1
	}
}	
Strategy for filter

Pre-order(root-first, left to right) Tree travasal

                    V: String
           S                     O
 (T: String, I: Int)      (T: String, I: Int)
   TI     T      I          TI     T      I

Scala에서 Tuple comparison이 쉬우니깐 이렇게 함.

쿼리의 복잡도(complexity)가 0.55를 넘으면 에러가 남

Finding neighborhood

특정 Point(Active Model)에 대해 같은 edge를 참조하여 해당 point를 다시 참조하는 경우이다. [A-B, B-C, A-C]의 경우 (A,B,C)는 neighborhood graph이다. [A-B, A-C, B-D, C-D]의 경우 neighbor graph는 없다.

Getting a recommendation

  1. (Active Model를 추천하는 경우) Maximum hop count가 2이고 [A-B, A-C, B-D, B-E, C-D]의 경우 candidates (A-B-E, 1), (A-B-D, 1), (A-C-D, 1)가 있고, middle hop count당 (hop count)-1을 point로 매기면 left fold에 따라 [(A-D, 1), (A-D, 1), (A-D, 1)] 그래프가 생기고 결과적으로 (A-D, 2) 가 제일 높은 포인트를 가지게된다.

  2. (Inactive Model를 추천하는 경우) [ A likes P1, B likes P1, B likes P2, C likes P1 ] 일 경우 (A, like)의 candidates는 ((P1, like), like)가 된다.

Note: Multi-hop query 처리를 최적화 시켜야함

JS API

특정 type을 가지고 있는 point를 model이라고 부른다. 데이터 모델을 생각하면 user, page 모두가 모델이 된다.

{
	Type string of subject model  : ID number of model,
	do | does | did | verb : Any verb as String,
	Type string of object model  : ID number of model,
}

코드의 가독성을 위해 verb, do, does, did를 이용할 수 있지만, 'verb'를 권장한다.