bonche
bonche

Reputation: 1

calling an external api using ngresource in angularjs

Am wondering is it possible fetch data from an external api using ngresource in angularjs.`

var brk = angular.module('service', ['ngResource']);

brk.factory('ListingFactory', function ($resource) {
    return $resource("http://bonches.cloudapp.net/product/index", {}, {     
        query: { method: 'GET', isArray: true },
        create: { method: 'POST' }
    })
});

brk.factory('ListingsFactory', function ($resource) {    
    return $resource('http://bonches.cloudapp.net/product/index', {}, {    
        show: { method: 'GET' },
        update: { method: 'PUT', params: {id: '@id'} },
        delete: { method: 'DELETE', params: {id: '@id'} }
    })
});

when i run that it maps the url over the enviroment am working under like localhost:8000/http://bonches.cloudapp.net/product/index.

Upvotes: 0

Views: 100

Answers (1)

alberto-bottarini
alberto-bottarini

Reputation: 1231

You can only if your server implements CORS, a way to make a cross-site request based on HTTP headers.

Take a look here how to configure CORS: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Upvotes: 1

Related Questions