Reputation: 133
I made a really simple Neo4j 2.0 Server Plugin that works great without any parameters. However, I'm not sure how I'm supposed to pass a string parameter to the plugin. I have one optional parameter called "criteria". This should be very simple. I'm just not very familiar with CURL, java, or 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;
}
I tried a few different ways with curl:
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"}
I've been following this page and it has an example of passing a parameter. Maybe I'm just overlooking something? http://docs.neo4j.org/chunked/snapshot/server-plugins.html
This is the json information I get back when I do a GET request on the url:
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"
} ]
}
Upvotes: 0
Views: 191
Reputation: 39915
You need to pass in the parameters in JSON format. Therefore it's crucial to specify the content type and to put the payload in quotes, so try
curl -X POST -H "Content-Type: application/json" -data '{ "criteria" : "thisorthat"}' http://icexad01:7474/db/data/ext/GetAll/graphdb/getLabelsForSearch
Upvotes: 2