Random Famous Quotes

FREEMIUM
By Andres Olvera | Updated 16 days ago | Data
Popularity

9.4 / 10

Latency

463ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Response returns an empty body

Rapid account: Smcgee 31
smcgee31
7 years ago

When using the API as described I get a response object, but the response.body is an empty object. No quote returned.

Rapid account: Andruxnet
andruxnet Commented 7 years ago

No problem

Rapid account: Smcgee 31
smcgee31 Commented 7 years ago

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.

Rapid account: Andruxnet
andruxnet Commented 7 years ago
Rapid account: Smcgee 31
smcgee31 Commented 7 years ago

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>

Rapid account: Andruxnet
andruxnet Commented 7 years ago

Yeah, sorry about that. Replace blob,json with blob.json()

Rapid account: Smcgee 31
smcgee31 Commented 7 years ago

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

Rapid account: Andruxnet
andruxnet Commented 7 years ago

Also, it appears you’re missing a .then() in your code

Try this:

https://gist.github.com/andruxnet/e20c6f4a436bce5095dcad89257576fd

Rapid account: Andruxnet
andruxnet Commented 7 years ago

Hey,

Please try changing this line:

method: POST,

to this:

method: “POST”,

note the quotes

Let me know how it goes

Rapid account: Smcgee 31
smcgee31 Commented 7 years ago

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. 😃

Rapid account: Andruxnet
andruxnet Commented 7 years ago

Can you share the code you’re using?

Join in the discussion - add comment below:

Login / Signup to post new comments