I am trying to update some information in my json server but I still don't seem to reach my end points. Am I setting mu urls correct. I have tried a couple times changing my url. In my mind I thinking I am doing the correct thing. But error messages telling me other wise. I would appreciate any guidance. Thanks in advance.
Component functions
const [author, setAuthor] = useState("");
const [text, setText] = useState("");
useEffect(() => {
const loadArticleInfo = async () => {
try {
const response = await axios.get(`http://localhost:5000/articles/${id}`)
setArticleInfo(response.data)
} catch (err) {
console.log(err);
}
};
loadArticleInfo();
}, [id]);
const addUpvote = async () => {
const response = await axios.put(`/articles/${id}/upvotes`, {...articleInfo, upvotes: articleInfo.upvotes + 1, });
const updatedArticle = response.data;
setArticleInfo(updatedArticle);
};
const addComment = async () => {
const temp_comments = [...articleInfo.comments, {author: author, text: text}];
console.log(temp_comments, "New Comment");
const response = await axios.put(`http://localhost:5000/articles/${id}/comments`, {...articleInfo, comments: temp_comments});
console.log(response.data)
setArticleInfo({...articleInfo, comments: response.data});
setAuthor("");
setText("");
Sample JSON
{
"articles": [
{
"id": "2",
"name": "learn-node",
"title": "How to Build a Node Server in 10 Minutes",
"content": [
"`In this article, ....."
],
"upvotes": 9,
"comments": [
{
"author": "anon",
"text": "Node really changed things for me since I no longer have to master PHP... JS all the way!"
},
{
"author": "Tester",
"text": "No!!! Not another server!"
}
Edited my put urls to this
const response = await axios.put(/articles/${id}/, {...articleInfo, upvotes: articleInfo.upvotes + 1, }