我制作了一个非常简单的Neo4j 2.0服务器插件,它在没有任何参数的情况下运行良好。但是,我不确定我应该如何将字符串参数传递给插件。我有一个名为“criteria”的可选参数。这应该很简单。我对CURL,java或REST不是很熟悉。
@Name( "getLabelsForSearch" )
@Description( "Get all labels that match the search criteria from the Neo4j graph database" )
@PluginTarget( GraphDatabaseService.class )
public Iterable<String> getLabelsForSearch( @Source GraphDatabaseService graphDb, @Description("The search criteria string") @Parameter (name = "criteria", optional = true) String criteria )
{
ArrayList<String> labels = new ArrayList<>();
labels.add(criteria);
try (Transaction tx = graphDb.beginTx())
{
for ( Label label : GlobalGraphOperations.at(graphDb).getAllLabels() )
{
labels.add(criteria);
//This is just for testing
labels.add(label.name());
}
tx.success();
}
return labels;
}
我尝试了几种不同的卷曲方法:
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch?criteria=thisorthat
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch/criteria/thisorthat
curl -X POST http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch -data { "criteria" : "thisorthat"}
我一直在关注此页面,它有一个传递参数的示例。也许我只是忽略了什么? http://docs.neo4j.org/chunked/snapshot/server-plugins.html
这是我在网址上发出GET请求时收到的json信息:
http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch/
{
"extends" : "graphdb",
"description" : "Get all labels that match the search criteria from the Neo4j graph database",
"name" : "getLabelsForSearch",
"parameters" : [ {
"description" : "The search criteria string",
"optional" : true,
"name" : "criteria",
"type" : "string"
} ]
}
答案 0 :(得分:2)
您需要以JSON格式传递参数。因此,指定内容类型并将有效负载放在引号中至关重要,因此请尝试
curl -X POST -H "Content-Type: application/json" -data '{ "criteria" : "thisorthat"}' http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch