April 2020
Intermediate to advanced
716 pages
18h 55m
English
We will use the Newsfeed API in the frontend to fetch the related posts and display these posts in the Newsfeed view. First, we will add a fetch method to make a request to the API, as shown in the following code.
client/post/api-post.js:
const listNewsFeed = async (params, credentials, signal) => { try { let response = await fetch('/api/posts/feed/'+ params.userId, { method: 'GET', signal: signal, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + credentials.t } }) return await response.json() } catch(err) { console.log(err) }}
This is the fetch method that will load the posts that are rendered in PostList, which is added as a child component to ...
Read now
Unlock full access