[英]Sending response body with Akka?
I have a Scala/akka-http project that has a reactjs frontend. 我有一个带有Reactjs前端的Scala / akka-http项目。 My route looks like this: 我的路线如下所示:
val quoteRoute = cors(){
pathPrefix("quote") {
get {
complete (HttpResponse(201, entity=
repository.
shuffleQuotes(starterQuotes)
))
}
}
}
This all works fine, and it prints out a string. 一切正常,并打印出一个字符串。 However, I have a react frontend that fetches the response like this: 但是,我有一个反应前端,它像这样获取响应:
function fetchQuote() {
fetch("http://localhost:8080/quote", {
method: 'GET'
})
.then(function (response) {
console.log(response)
})
.catch(function (err) {
console.log("quote not generated" + err)
});
}
When I console.log the response, it gets relevant things like the status code. 当我console.log响应时,它会得到相关的信息,例如状态码。 But it says that bodyused is false, and I cannot find the actual string I want. 但是它说bodyused是错误的,并且我找不到我想要的实际字符串。 I'm not sure what the issue is? 我不确定是什么问题?
Thanks! 谢谢!
You likely need something like this: 您可能需要这样的东西:
function fetchQuote() {
fetch("http://localhost:8080/quote", {
method: 'GET'
})
.then(function (response) {
return response.json()
})
.then(function (data) {
console.log(data);
})
.catch(function (err) {
console.log("quote not generated" + err)
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.