switched to axios instead of fetch and now it’s working fine locally. I think the ReadableStream is a fetch thing but I didn’t dive too deep to find out much about it. Thanks for your help.
Ok, so now I have it running locally using npm package called lite-server. Seems to be running fine and the response I get back is the same as the one using the CodePen. Also whether I grab blob or response it is the same response…
<pre><code>
Response {type: “cors”, url: “https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous”, redirected: false, status: 200, ok: true…}
body: ReadableStream
locked: locked proto: Object
bodyUsed: false
headers: Headers proto: Headers
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous" proto: Response</code></pre>
Yeah the ‘POST’ does need to be in quotes. And we’re getting close but blob.json returns function json() { [ native code ] } and that is all.
Would executing this code inside a CodePen make a difference or make this not work right? http://codepen.io/smcgee31/pen/JNKZKQ?editors=1011
Here’s the function that I am using (node environment):
<pre><code> function getQuote() {
return fetch(‘https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous’, {
method: POST,
headers: {
“X-Mashape-Key”: “b6tCZGODOTmshRX3SGwKX39eANfup1NqESSjsnPp9aB0mxbvHF”,
“Content-Type”: “application/x-www-form-urlencoded”,
“Accept”: “application/json”
}
})
.then((response) => {
console.log(response); // so that I can see the response - looks like response.body is where the quote would be
return handleResponse(response)
})
.catch((error) => {
return handleError(error);
})
};</code></pre>
Hope there aren’t any embarrasing sytax errors. 😃
No problem
switched to axios instead of fetch and now it’s working fine locally. I think the
ReadableStream
is a fetch thing but I didn’t dive too deep to find out much about it. Thanks for your help.It works, check it out:
http://codepen.io/andruxnet/pen/EmgMZa?editors=1011
Ok, so now I have it running locally using npm package called lite-server. Seems to be running fine and the response I get back is the same as the one using the CodePen. Also whether I grab
blob
orresponse
it is the same response…<pre><code>
Response {type: “cors”, url: “https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous”, redirected: false, status: 200, ok: true…}
body: ReadableStream
locked: locked
proto: Object
bodyUsed: false
headers: Headers
proto: Headers
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous"
proto: Response</code></pre>
Yeah, sorry about that. Replace blob,json with blob.json()
Yeah the ‘POST’ does need to be in quotes. And we’re getting close but
blob.json
returnsfunction json() { [ native code ] }
and that is all.Would executing this code inside a CodePen make a difference or make this not work right?
http://codepen.io/smcgee31/pen/JNKZKQ?editors=1011
Also, it appears you’re missing a .then() in your code
Try this:
https://gist.github.com/andruxnet/e20c6f4a436bce5095dcad89257576fd
Hey,
Please try changing this line:
method: POST,
to this:
method: “POST”,
note the quotes
Let me know how it goes
Here’s the function that I am using (node environment):
<pre><code> function getQuote() {
return fetch(‘https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous’, {
method: POST,
headers: {
“X-Mashape-Key”: “b6tCZGODOTmshRX3SGwKX39eANfup1NqESSjsnPp9aB0mxbvHF”,
“Content-Type”: “application/x-www-form-urlencoded”,
“Accept”: “application/json”
}
})
.then((response) => {
console.log(response); // so that I can see the response - looks like
response.body
is where the quote would bereturn handleResponse(response)
})
.catch((error) => {
return handleError(error);
})
};</code></pre>
Hope there aren’t any embarrasing sytax errors. 😃
Can you share the code you’re using?