LoginSignup
1
2

More than 5 years have passed since last update.

CurlでRestAPIからneo4jを使う

Last updated at Posted at 2016-04-19

neo4jを用いたアプリケーション作成の際,どんな値をとってくるのかなどちょっとしたテストのときにcurlコマンドで値を確認したくなったりしますよね

リファレンス

The Neo4j Manual v2.3.3

コマンド

Cypherクエリをpostして値を受け取りたい

コマンド
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"query":"match (n:Issue) return n limit 2", "params":{}}'  http://localhost:7474/db/data/cypher
結果
{
  "columns" : [ "n" ],
  "data" : [ [ {
    "outgoing_relationships" : "http://localhost:7474/db/data/node/9762/relationships/out",
    "labels" : "http://localhost:7474/db/data/node/9762/labels",
    "data" : {
      "id" : 122452946,
      "html_url" : "https://github.com/shu920921/AwareTweet/issues/42",
      "title" : "edit comment in Japanese to English",
      "repository_url" : "https://api.github.com/repos/shu920921/AwareTweet",
      "updated_at" : "2015-12-16T09:25:44Z",
      "comments_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/42/comments",
      "state" : "closed",
      "events_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/42/events",
      "created_at" : "2015-12-16T08:33:12Z",
      "number" : 42,
      "labels_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/42/labels{/name}",
      "user" : "shu920921",
      "url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/42"
    },
    "all_typed_relationships" : "http://localhost:7474/db/data/node/9762/relationships/all/{-list|&|types}",
    "traverse" : "http://localhost:7474/db/data/node/9762/traverse/{returnType}",
    "self" : "http://localhost:7474/db/data/node/9762",
    "property" : "http://localhost:7474/db/data/node/9762/properties/{key}",
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/9762/relationships/out/{-list|&|types}",
    "properties" : "http://localhost:7474/db/data/node/9762/properties",
    "incoming_relationships" : "http://localhost:7474/db/data/node/9762/relationships/in",
    "extensions" : {
    },
    "create_relationship" : "http://localhost:7474/db/data/node/9762/relationships",
    "paged_traverse" : "http://localhost:7474/db/data/node/9762/paged/traverse/{returnType}{?pageSize,leaseTime}",
    "all_relationships" : "http://localhost:7474/db/data/node/9762/relationships/all",
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/9762/relationships/in/{-list|&|types}",
    "metadata" : {
      "id" : 9762,
      "labels" : [ "Issue" ]
    }
  } ], [ {
    "outgoing_relationships" : "http://localhost:7474/db/data/node/9763/relationships/out",
    "labels" : "http://localhost:7474/db/data/node/9763/labels",
    "data" : {
      "id" : 122441691,
      "html_url" : "https://github.com/shu920921/AwareTweet/issues/41",
      "title" : "Fix Login Page",
      "repository_url" : "https://api.github.com/repos/shu920921/AwareTweet",
      "updated_at" : "2015-12-16T06:51:20Z",
      "comments_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/41/comments",
      "state" : "open",
      "events_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/41/events",
      "created_at" : "2015-12-16T06:51:20Z",
      "number" : 41,
      "labels_url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/41/labels{/name}",
      "user" : "shu920921",
      "url" : "https://api.github.com/repos/shu920921/AwareTweet/issues/41"
    },
    "all_typed_relationships" : "http://localhost:7474/db/data/node/9763/relationships/all/{-list|&|types}",
    "traverse" : "http://localhost:7474/db/data/node/9763/traverse/{returnType}",
    "self" : "http://localhost:7474/db/data/node/9763",
    "property" : "http://localhost:7474/db/data/node/9763/properties/{key}",
    "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/9763/relationships/out/{-list|&|types}",
    "properties" : "http://localhost:7474/db/data/node/9763/properties",
    "incoming_relationships" : "http://localhost:7474/db/data/node/9763/relationships/in",
    "extensions" : {
    },
    "create_relationship" : "http://localhost:7474/db/data/node/9763/relationships",
    "paged_traverse" : "http://localhost:7474/db/data/node/9763/paged/traverse/{returnType}{?pageSize,leaseTime}",
    "all_relationships" : "http://localhost:7474/db/data/node/9763/relationships/all",
    "incoming_typed_relationships" : "http://localhost:7474/db/data/node/9763/relationships/in/{-list|&|types}",
    "metadata" : {
      "id" : 9763,
      "labels" : [ "Issue" ]
    }
  } ] ]
}

基本的には

雛形
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"query":"クエリ", "params":{}}'  http://localhost:7474/db/data/cypher

ですのですぐ使えると思います.
今回はreturnでノードを取得していますが,これはCypherクエリを投げているので,createやdeleteも行うことができます.

プログラムからneo4jを扱うためのライブラリは多数存在しますが,なんだかんだjson形式で受け取った方が自在に加工できるので楽なような気がしてます.

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2