I am making a GET
request to a third party API from my server. The request returns a JSON
response.
Now that I have that JSON
, I want to make a fetch API request from the front end to the server in order to retrieve that JSON
and display it on the front end.
Currently my setup is like this:
www.siteA.com/backend > This is a page on the backend.
It makes a request to a third party site that returns some json data
www.siteA.com/frontend > This is the front end of the site.
I make a fetch request to www.siteA.com/backend to retrieve the json data that
was returned from the backend api request to the third party site.
When I examine the response I get from my fetch request from www.siteA.com/frontend to www.siteA.com/backend, it is receiving literally the whole html page, whereas I only want the JSON data.
How do I retrieve the json from the front end?
Are you able to provide us more information? Are you just looking for a way to get data from an API? If yes, the easiest option in my opinion is to use the fetch()
method
fetch('www.your-restapi.com/something-here')
.then(res=> {
return res.json()
})
.then(data => {
// your data is available
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.