Placeholders in JSON - is there a better method?
Anyone have a favorite free service that has dummy JSON that can be queried over HTTP?
How to POST data to JsonPlaceholder fake server?
Best JSON Placeholder/Server?
What can I use instead of JSONPlaceholder?
Is JSONPlaceholder good for production testing?
Does JSONPlaceholder support authentication?
Videos
I'm working on a Python script to generate all of the directories and base files I typically create when making a new project. I have a JSON file which stores the directories, the files in each, and the contents of those files.
Right now I have a placeholder value of "<app_name>" in the JSON object that needs to be replaced with the app name provider via user input, but I feel like this is not the right approach for JSON. Is there a standard way to have a placeholder value in JSON objects, or is there a more appropriate way of storing this information?
» npm install @freepi/jsonplaceholder
When testing non-application-specific code (like middleware or generic architecture), I often would like to have something like placehold.it but for JSON. Something I can perform HTTP requests against when I don't necessarily care about what type of data I get back, as long as I get something. Do any of you know of a service like that?
The issue is the form.
Here's the working code:
<html>
<head>
<meta http-equiv="Content-Type" charset="UTF-8">
</head>
<body>
<h1>Please type in new item data:</h1><br>
<label class="add_label"><b> userId: </b></label>
<input type="number" class="add_input" id="new_userId" name="new_userId" value="">
<br>
<label class="add_label"><b> title: </b></label>
<input type="text" class="add_input" id="new_title" name="new_title" value="">
<br>
<label class="add_label"><b> body: </b></label>
<input type="text" class="add_input" id="new_body" name="new_body" value="">
<button id="add_btn2" onclick="New()">Submit</button>
<script>
function New() {
var userid = document.getElementById("new_userId").value;
var new_title = document.getElementById("new_title").value;
var new_body = document.getElementById("new_body").value;
console.log("Input Data: " + userid + " " + new_title + " " + new_body);
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
title: new_title,
body: new_body,
userId: userid
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(json => {
console.log('response: ' + JSON.stringify(json));
})
}
</script>
</body>
</html>
Check the console to see the response
First you need to prevent the form from submitting, if not it will refresh the page. You can try this:
In Form
... <button id = "add_btn2" onclick = "New(event)" type = "submit">Submit</button> ...In function
function New(e) { e.preventDefault() ...As stated here JSONPlaceholder Guide, the resource will not be really created. Successful request will return a
jsonobject based on form-data you've sent. Just check your browser log, check if the responses just like what the documentation said.