I'm currently working a Neo4j REST API wrapper for nodejs (node-neo4j).
Just making it ready for v2.0 of Neo4j
My fork: https://github.com/Stofkn/node-neo4j of https://github.com/philippkueng/node-neo4j
Is it possible to use the REST API to create a node with an integer like:
{ name: 'Kristof', age: 77 }
It creates a Node like this { name: 'Kristof', age: '77' }
Is the only workaround a Cypher query or a server plugin?
It should create the node with an numeric property, if it doesn't it's a bug but the code for that has been around for a long while.
For 2.0 I'd suggest to focus on the transactional endpoint first and add support for the REST API later on :)
Thanks for your help Michael.
I had to remove the type 'form' otherwise the integer is interpreted as a string.
My solution for a simple node creation without labels:
var request = require('superagent');
request
.post(this.url + '/db/data/node')
.send(node)
// .type('form') remove this line
.set('Accept', 'application/json')
.end(function(result){
if(typeof result.body !== 'undefined')
that.addNodeId(result.body, callback);
else
callback(new Error('Response is empty'), null);
});
Related
In Artillery, how can I capture the attribute of a random index in a JSON array returned from a GET, so my subsequent POSTs are evenly distributed across the resources?
https://artillery.io/docs/http-reference/#extracting-and-reusing-parts-of-a-response-request-chaining
I'm using serverless artillery to run a load test, which under the hood uses artillery.io .
A lot of my scenarios look like this:
-
get:
url: "/resource"
capture:
json: "$[0].id"
as: "resource_id"
-
post:
url: "/resource/{{ resource_id }}/subresource"
json:
body: "Example"
Get a list of resources, and then POST to one of those resources.
As you can see, I am using capture to capture an ID from the JSON response. My problem is that it is always getting the id from the first index of the array.
This will mean in my load test I end up absolutely battering one single resource rather than hitting them evenly which will be a more likely scenario.
I would like to be able to do something like:
capture:
json: "$[RANDOM].id
as: "resource_id"
but I have been unable to find anything in the JSONPath definition that would allow me to do so.
Define setResourceId function in custom JS code and to tell Artillery to load your custom code, set config.processor to the JS file path:
processor: "./custom-code.js"
- get:
url: "/resource"
capture:
json: "$"
as: "resources"
- function: "setResourceId"
- post:
url: "/resource/{{ resourceId }}/subresource"
json:
body: "Example"
custom-code.js file containing the below function
function setResourceId(context, next) {
const randomIndex = Math.round(Math.random() * context.vars.resources.length);
context.vars.resourceId = context.vars.resources[randomIndex].id;
}
Using this version:
------------ Version Info ------------
Artillery: 1.7.9
Artillery Pro: not installed (https://artillery.io/pro)
Node.js: v14.6.0
OS: darwin/x64
The answer above didn't work for me.
I got more info from here, and got it working with the following changes:
function setResourceId(context, events, done) {
const randomIndex = Math.round(Math.random() * (context.vars.resources.length - 1));
context.vars.resourceId = context.vars.resources[randomIndex].id;
return done();
}
module.exports = {
setResourceId: setResourceId
}
I am new to Ember and is trying to create a small application using version beta 2.3.0.
Provided a country and zipcode, I am trying to get the city and zipcode.
With Mirage and a custom serializer (I am using the same format as of real json) my code works perfectly.
However, with the real API, the Promise remains in Pending state. There is no error in console.
And the logs in my serializer does not display when using real service indicating that the serializer is not executing.
Has anyone faced a similar issue before. Please help.
In my controller, I am finding the record as:
this.store.find('address', zipcode).then(
function(address) {
console.log("Hello Got Address");
});
My adapters/application.js :
export default DS.RESTAdapter.extend({
host: 'http://real_url_here',
pathForType: function(type) {
return '';
}});
The JSONAPISerialier is overriden in serializers/application.js as:
export default DS.JSONAPISerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
.......... // Code goes here
}});
In my mirage/config.js, I am returning sample json for 2 zipcodes and at the end I have added:
this.passthrough('http://real_url_here/**');
to invoke real service for other zipcodes
I got the answer finally :).
I had to disable the mirage in development :
To disable in development,
// config/environment.js
...
if (environment === 'development') {
ENV['ember-cli-mirage'] = {
enabled: false
}}
I'm using Ember-Data 1.0.0.Beta-9 and Ember 1.7 to consume a REST API via DreamFactory's REST Platform. (http://www.dreamfactory.com).
I've had to extend the RESTAdapter in order to use DF and I've been able to implement GET and POST requests with no problems. I am now trying to implement model.save() (PUT) requests and am having a serious hiccup.
Calling model.save() sends the PUT request with the correct data to my API endpoint and I get a 200 OK response with a JSON response of { "id": "1" } which is what is supposed to happen. However when I try to access the updated record all of the properties are empty except for ID and the record on the server is not updated. I can take the same JSON string passed in the request, paste it into the DreamFactory Swagger API Docs and it works no problem - response is good and the record is updated on the DB.
I've created a JSBin to show all of the code at http://emberjs.jsbin.com/nagoga/1/edit
Unfortunately I can't have a live example as the servers in question are locked down to only accept requests from our company's public IP range.
DreamFactory provides a live demo of the API in question at
https://dsp-sandman1.cloud.dreamfactory.com/swagger/#!/db/replaceRecordsByIds
OK in the end I discovered that you can customize the DreamFactory response by adding a ?fields=* param to the end of the PUT request. I monkey-patched that into my updateRecord method using the following:
updateRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record);
var adapter = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
// hack to make DSP send back the full object
adapter.ajax(adapter.buildURL(type.typeKey) + '?fields=*', "PUT", { data: data }).then(function(json){
// if the request is a success we'll return the same data we passed in
resolve(json);
}, function(reason){
reject(reason.responseJSON);
});
});
}
And poof we haz updates!
DreamFactory has support for tacking several params onto the end of the requests to fully customize the response - at some point I will look to implement this correctly but for the time being I can move forward with my project. Yay!
EmberData is interpreting the response from the server as an empty object with an id of "1" an no other properties in it. You need to return the entire new object back from the server with the changes reflected.
I have just started getting familiar with dojo and creating widgets and have a web UI which I would like to now populate with data. My question is merely to get some references or ideas on how to do this. My databases are all sql server 2008 and I usually work with microsoft.net. I thought that I would probably have to create a service that calls the sql queries and converts the results into json and feed that into the widgets whether it be the datagrid or charts. Just not sure how to do this and if it is indeed possible to do that. Any ideas appreciated.
EDIT:
store = new dojo.data.ItemFileWriteStore({
url: "hof-batting.json"
});
ngrid = new dojox.grid.DataGrid({
store: store,
id: 'ngrid',
structure: [
{ name: "Search Term", field: "searchterm", width: "10%" },
{ name: "Import Date", field: "importDate", width: "10%" }
]
}, "grid");
ngrid.startup();
I want to add data returned from my web service to this datagrid and use the same principle to add data to a chart.
Your describe exactly what you need to do.
We use C# to query our database to get the data and then convert it to json. We use multiple techniques right now for json serialization. I would recommend using JSON.NET. It is what the .NET MVC team is going to use. I would not use the DataContractSerialization that is currently part of .NET.
http://json.codeplex.com/
We sometimes put JSON right on the page and the javascript accesses it as a page variable. Other times we call services in .NET. We use WCF and we have also used an .ashx file to give the web client json data.
The structure of the json will be the contract between your dojo widgets and web server. I would use what the chart widgets or store will need to start the process of defining the contract.
EDIT
WCF Interface
[OperationContract]
[WebInvoke(Method="POST", UriTemplate = "/data/{service}/",
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
String RetrieveData(string service, Stream streamdata);
The implementation returns a string that is the json. This gets sent to the browser as json, but it's wrapped by .NET by an xml node. I have a utility function that cleans it.
MyUtil._xmlPrefix =
'<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">';
MyUtil._xmlPostfix = '</string>';
MyUtil.CleanJsonResponse = function(data) {
// summary:
// a method that cleans a .NET response and converts it
// to a javascript object with the JSON.
// The .NET framework, doesn't easily allow for custom serialization,
// so the results are shipped as a string and we need to remove the
// crap that Microsoft adds to the response.
var d = data;
if (d.startsWith(MyUtil._xmlPrefix)) {
d = d.substring(MyUtil._xmlPrefix.length);
}
if (d.endsWith(MyUtil._xmlPostfix)) {
d = d.substring(0, d.length - MyUtil._xmlPostfix.length);
}
return dojo.fromJson(d);
};
// utility methods I have added to string
String.prototype.startsWith = function(str) {
return this.slice(0, str.length) == str;
};
String.prototype.endsWith = function(str) {
return this.slice(-str.length) == str;
};
I'm populating a YUI DataTable via JSON, starting from the sample code DataTable + DataSource.Get + JSON Data. Despite its promising title, this sample uses JSONP, not straight JSON. In my case, I'm querying with a relative URL, so I don't need (or want) JSONP.
My code defines a data source and schema like this:
var dataSource = new Y.DataSource.Get({ source: "myLocalUrl.json" });
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: { resultListLocator: "result.path.to.array", resultFields: ["key1", "key2"]}
});
Nowhere in here does it specify JSONP, but apparently that's the default behavior-- despite the security warnings in the JSONP documentation. Perhaps I'm missing something obvious, but I've checked the API docs for Y.DataSource and Y.DataSource.Get, and neither is particularly enlightening.
I had better luck with DataSource.IO
var dataSource = new Y.DataSource.IO({ source: "myLocalUrl.json" });
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: { resultListLocator: "result.path.to.array", resultFields: ["key1", "key2"]}
});