I have set-up a few Netflix OSS microservices (Eureka, Falcor sidecar) as well as a very basic Falcor set-up in order to test the functionality. I am trying to make a call from the client-side of Falcor to an external API, whose endpoint is http://localhost:8001/customer/customers. In my index.js file I have:
app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) {
return new falcorRouter([
{
route: "customers.length",
get: function (pathset) {
return http.get("http://localhost:8001/customer/customers")
.then(function (json) {
return {
path: pathset,
value: $atom(json.length)
};
});
}
}
]);
}));
Then in my client-side index.html:
<html>
<head>
<script src="js/falcor.browser.js"></script>
<script>
var model = new falcor.Model({source: new falcor.HttpDataSource('/model.json') });
model.
get("customers.length").
then(function(response) {
console.log(response);
});
</script>
</head>
<body>
</body>
</html>
If I hit the http://localhost:8001/customer/customers API manually, I get back a JSON object like this:
[
{
"customerId": 1,
"customerName": "Pierre"
},
{
"customerId": 2,
"customerName": "Paula"
}
]
However, my console.log is outputting an error object like this:
[{path: ["customers","length"],
value: {message: "undefined is not a function"}}]
I am not too interested at this stage in exactly what format object I get back, I just want something to play with. How do I amend my router to get the data I am expecting back?
Thanks
You should try this...
SERVER
CLIENT
JSON FILE
OUTPUT ON BROWSER'S CONSOLE