I want to save data to a static JSON file sitting on my server using a Fetch POST request.
Is this possible to do? If so any tips or advice would be appreciated
My Javascript code to try save data to my JSON file.
fetch('link-data.json', {
method:'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type':'application/json'
},
body:JSON.stringify({
id:3,
title:"website_title",
url:"www.example.com",
description:"Hi_there_im_a_description"
})
})
.then((res) => res.json())
.then((data) => console.log(data))
My JSON file I want to save the data to.
[
{
"id": 0,
"title": "Twitter. It's what's happening.",
"url": "https://twitter.com/?lang=en",
"description": "From breaking news and entertainment to sports and politics, get the full story with all the live commentary."
},
{
"id": 1,
"title": "Netflix - Watch TV Shows Online, Watch Movies Online",
"url": "https://www.netflix.com/",
"description": "Watch Netflix movies & TV shows online or stream right to your smart TV, game console, PC, Mac, mobile, tablet and more."
},
{
"id": 2,
"title": "Facebook - Log In or Sign Up",
"url": "https://www.facebook.com/",
"description": "Create an account or log into Facebook. Connect with friends, family and other people you know. Share photos and videos, send messages and get updates."
}
]
www.example.com
. You need to set up your own endpoint for this to work. – Brandon Dyer Feb 13 '20 at 21:11