Getting error has been blocked by CORS policy when making api call
up vote
0
down vote
favorite
I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint
This is what the error exactly looks like
localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
I have previously encountered this error but that was when I was trying to make a local API call.
I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.
Any ideas or fixes?
I am using axios for making api calls
axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {
[Update:] Can someone also help me in figuring out how we can use it with Promise.
let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)
return Promise.all(Base_url, StaffPick).then(response => {
Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map
javascript ajax api
|
show 2 more comments
up vote
0
down vote
favorite
I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint
This is what the error exactly looks like
localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
I have previously encountered this error but that was when I was trying to make a local API call.
I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.
Any ideas or fixes?
I am using axios for making api calls
axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {
[Update:] Can someone also help me in figuring out how we can use it with Promise.
let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)
return Promise.all(Base_url, StaffPick).then(response => {
Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map
javascript ajax api
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
@SakoBu you clearly didn't try it usingXMLHttpRequest()
orfetch()
which is where CORS kicks in
– charlietfl
Nov 10 at 20:24
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint
This is what the error exactly looks like
localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
I have previously encountered this error but that was when I was trying to make a local API call.
I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.
Any ideas or fixes?
I am using axios for making api calls
axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {
[Update:] Can someone also help me in figuring out how we can use it with Promise.
let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)
return Promise.all(Base_url, StaffPick).then(response => {
Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map
javascript ajax api
I am getting the following error when I am trying to make an api call to kickstarter Staff pick json endpoint
This is what the error exactly looks like
localhost/:1 Access to XMLHttpRequest at
'https://www.kickstarter.com/discover/recommended?format=json' from
origin 'http://localhost:3000' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
I have previously encountered this error but that was when I was trying to make a local API call.
I known I can enable cors on my browser which might possibly fix the error but I am trying to avoid it.
Any ideas or fixes?
I am using axios for making api calls
axios.get("https://www.kickstarter.com/discover/recommended?format=json").then(response => {
[Update:] Can someone also help me in figuring out how we can use it with Promise.
let Base_url = axios.get(base_url)
let StaffPick = axios.get(staffPick)
return Promise.all(Base_url, StaffPick).then(response => {
Where staff pick is https://www.kickstarter.com/discover/recommended?format=json
and
base_url is: http://coincap.io/map
javascript ajax api
javascript ajax api
edited Nov 10 at 20:39
asked Nov 10 at 20:15
KuchBhi
621218
621218
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
@SakoBu you clearly didn't try it usingXMLHttpRequest()
orfetch()
which is where CORS kicks in
– charlietfl
Nov 10 at 20:24
|
show 2 more comments
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
@SakoBu you clearly didn't try it usingXMLHttpRequest()
orfetch()
which is where CORS kicks in
– charlietfl
Nov 10 at 20:24
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
@SakoBu you clearly didn't try it using
XMLHttpRequest()
or fetch()
which is where CORS kicks in– charlietfl
Nov 10 at 20:24
@SakoBu you clearly didn't try it using
XMLHttpRequest()
or fetch()
which is where CORS kicks in– charlietfl
Nov 10 at 20:24
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Try it like this and it should work:
fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));
Or the equivalent with axios...
Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15
Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere
Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Try it like this and it should work:
fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));
Or the equivalent with axios...
Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15
Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere
Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
add a comment |
up vote
1
down vote
accepted
Try it like this and it should work:
fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));
Or the equivalent with axios...
Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15
Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere
Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Try it like this and it should work:
fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));
Or the equivalent with axios...
Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15
Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere
Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Try it like this and it should work:
fetch(
'https://cors-anywhere.herokuapp.com/https://www.kickstarter.com/discover/recommended?format=json')
.then(response => response.json())
.then(data => console.log(data));
Or the equivalent with axios...
Here is live demo on code sandbox: https://codesandbox.io/s/ox7wz9ny15
Instead of writing our own proxy server we're using this one: https://github.com/Rob--W/cors-anywhere
Note: if you want to use this in production I would recommend writing your own proxy server... More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
edited Nov 10 at 20:38
answered Nov 10 at 20:28
SakoBu
681317
681317
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
add a comment |
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
1
1
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
An explanation of why it should work would be helpful
– charlietfl
Nov 10 at 20:33
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
Also, if you include how we might be able to use it promise.all? Take this as my second URL: coincap.io/map (updating the code for the same)
– KuchBhi
Nov 10 at 20:36
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
@KuchBhi You had a CORS issue with solved it... This is a seperate question about how to use promise.all in axios... Here are the docs: github.com/axios/axios
– SakoBu
Nov 10 at 21:09
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243031%2fgetting-error-has-been-blocked-by-cors-policy-when-making-api-call%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If an API is not CORS enabled ( or serves JSONP) you need to use a proxy either on server you control or a third party service
– charlietfl
Nov 10 at 20:18
@charlietfl Thanks a lot for your answer. Can you please explain it briefly? Can you suggest a way via which i can get Kickstarter data?
– KuchBhi
Nov 10 at 20:21
Do a web search for "ajax proxy"
– charlietfl
Nov 10 at 20:21
Seems fine when simply hitting that end-point from a browser... Share your get request code here...
– SakoBu
Nov 10 at 20:22
@SakoBu you clearly didn't try it using
XMLHttpRequest()
orfetch()
which is where CORS kicks in– charlietfl
Nov 10 at 20:24