Created
April 28, 2021 22:56
-
-
Save onedebos/98d45ac1d613230a78e20cb574782d8e to your computer and use it in GitHub Desktop.
methods that handle getting the post, author and featured image from our server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import { POSTS_API_URL, AUTHORS_API_URL, MEDIA_API_URL } from './constants'; | |
export const getAllPostsFromServer = async () => { | |
// get all posts from Server | |
try { | |
const { data } = await axios.get(POSTS_API_URL); | |
return data; | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
export const getAuthor = async (id) => { | |
try { | |
const { | |
data: { name }, | |
} = await axios.get(`${AUTHORS_API_URL}/${id}`); | |
return name; | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
export const getFeaturedImage = async (id) => { | |
try { | |
const res = await axios.get(`${MEDIA_API_URL}/${id}`); | |
return res.data.guid.rendered; | |
} catch (error) { | |
console.log(error); | |
return ''; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment