Kimono labs API request


#1

l have created an api with kimonolabs and am trying to make a request from that endpoint.
this doesnt seem to work…

.controller(‘maritimCtrl’, [’$scope’,’$http’, functio($scope, $http){
$http.get(‘http://www.kimonolabs.com/api/c7exfow8?apikey=xVEo5Biu1o3X3AFxId440GGc2WvoCrnk’).then(function(resp) {
console.log(‘Success’, resp);
console.log(resp.data);
}, function(err) {
console.error(‘ERR’, err);
})
}]);

any ideas


Kimonolabs: how to scrap web pages and convert them to RSS feed
#2

looks like your call to the kimono API is alright. but you have a typo in your angular controller definition:

.controller('maritimCtrl', ['$scope','$http', functio($scope, $http){

is missing the n at the end of function. should be:

.controller('maritimCtrl', ['$scope','$http', function($scope, $http){

#3

.controller(‘maritimeCtrl’, [’$scope’,’$http’, function($scope, $http){
$http.get(‘http://www.kimonolabs.com/api/c7exfow8?apikey=xVEo5Biu1o3X3AFxId440GGc2WvoCrnk’).then(function(resp) {
console.log(‘Success’, resp);
console.log(resp.data);
}, function(err) {
console.error(‘ERR’, err);
})
}]);


#4

am still getting an error!!!

XMLHttpRequest cannot load http://www.kimonolabs.com/api/c7exfow8?apikey=xVEo5Biu1o3X3AFxId440GGc2WvoCrnk. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.

ERR Object {data: null, status: 0, config: Object, statusText: “”}


#5

Ah, I see now, the problem is that you haven’t configured CORS support for your API. See how here:

Basically visit your api detail page and enter the domain you are making these calls from (e.g. mydomain.com):
https://www.kimonolabs.com/apis/c7exfow8#api

Basically because this is a front end call, the request is being made from some client somewhere. This request is going to be rejected (for security reasons) unless you specifically approve requests from clients on that domain. For local testing, the domain you’ll probably want is localhost.

If you don’t want to use CORS or cannot for some reason, then alternatively you can use JSONP to get around the security issue. Here’s an article from the AngularJS docs on how to do use JSONP:
https://docs.angularjs.org/api/ng/service/$http#jsonp

With JSONP you don’t need a CORS domain, it should work as is.


#6

l have tried the localhost CORS DOMAIN but it still does not seem to work


#7

what is the “Access-Control-Allow-Origin: {DOMAIN} response header” about?
l think this must help


Pouchdb & kimonolabs - help
#8

l have got it using the jsonp method,thanks

.controller(‘maritimeCtrl’, [’$scope’,’$http’, function($scope, $http){
$http.jsonp(‘https://www.kimonolabs.com/api/4wfjeevq/?callback=JSON_CALLBACK’)
.success(function(resp) {
console.log(‘Success’, resp.results);
$scope.news = resp.results.MaritimeNews;
}, function(err) {
console.error(‘ERR’,err);
});
}])