Search code examples
angularjsresttitanrexster

How to Format Rexster POST to Add an Edge to a Titan Graph


I'm attempting add an edge to my Titan Server 0.4.4 graph using an AngularJS resource. The resource looks like this:

'use strict';
angular.module('storymapApp').factory('edgeResource', function ($resource) {
var EdgeResource = $resource('http://localhost:8182/graphs/graph/edges?_outV=:outId&label=:label&_inV=:inId', {outId: "@outId", inId: "@inId", label: "@label"}, {
    update: {method: 'PUT', isArray: false},
    outedge: {method: 'POST',
        transformResponse: function(data, headers){
            // deserialize the JSON response string
            data = angular.fromJson(data);
            data = data.results;
            return data;
        },
        isArray: true}
    });

    return EdgeResource;
});

This code generates a POST like this:

http://localhost:8182/graphs/graph/edges?_outV=120028&label=contains&_inV=160076

which returns the following 500 error message:

{"message":"An error occurred while generating the response object","error":"Edge cannot be found or created.  Please check the format of the request."}

Where is the formatting issue in the request?


Solution

  • Can you change your angularjs code to POST the request as JSON (instead of formatting the parameters to query string)? Set your Content-Type to application/json as well (though angular may be doing that for you already. Those things should fix your problem.