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>&nbsp;userId:&nbsp; </b></label>
  <input type="number" class="add_input" id="new_userId" name="new_userId" value="">
  <br>
  <label class="add_label"><b>&nbsp;title:&nbsp;</b></label>
  <input type="text" class="add_input" id="new_title" name="new_title" value="">
  <br>
  <label class="add_label"><b>&nbsp;body:&nbsp;</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

Answer from saintlyzero on Stack Overflow
๐ŸŒ
JSONPlaceholder
jsonplaceholder.typicode.com
JSONPlaceholder - Free Fake REST API
JSONPlaceholder comes with a set of 6 common resources: Note: resources have relations. For example: posts have many comments, albums have many photos, ...
๐ŸŒ
JSONPlaceholder
jsonplaceholder.typicode.com โ€บ guide
JSONPlaceholder - Guide
fetch('https://jsonplaceholder.typicode.com/posts', { method: 'POST', body: JSON.stringify({ title: 'foo', body: 'bar', userId: 1, }), headers: { 'Content-type': 'application/json; charset=UTF-8', }, }) .then((response) => response.json()) .then((json) => console.log(json));
Top answer
1 of 2
4

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>&nbsp;userId:&nbsp; </b></label>
  <input type="number" class="add_input" id="new_userId" name="new_userId" value="">
  <br>
  <label class="add_label"><b>&nbsp;title:&nbsp;</b></label>
  <input type="text" class="add_input" id="new_title" name="new_title" value="">
  <br>
  <label class="add_label"><b>&nbsp;body:&nbsp;</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

2 of 2
2
  1. 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() ...

  2. As stated here JSONPlaceholder Guide, the resource will not be really created. Successful request will return a json object based on form-data you've sent. Just check your browser log, check if the responses just like what the documentation said.

๐ŸŒ
GitHub
github.com โ€บ typicode โ€บ jsonplaceholder
GitHub - typicode/jsonplaceholder: A simple online fake REST API server ยท GitHub
JSONPlaceholder is a simple fake REST API for testing and prototyping. It's like an image placeholder but for web developers.
Starred by 5.2K users
Forked by 594 users
Languages ย  HTML 68.1% | JavaScript 31.9%
๐ŸŒ
Eviltester
apichallenges.eviltester.com โ€บ practice-sites โ€บ jsonplaceholder
JSON Placeholder - Simulator API - Example API
JSON Placeholder is an API that returns canned data. It also simulates the effects of update methods like POST, PUT, DELETE, PATCH by returning what would have happened if the request you made had taken effect.
๐ŸŒ
JSON Placeholder
arnu515.github.io โ€บ jsonplaceholder-api-docs
JSON Placeholder
delDelete a post ยท Documentation Powered by ReDoc ยท Download OpenAPI specification:Download ยท Free fake API for testing and prototyping. JSON Placeholder's guide ยท 200 ยท All went well ยท get/posts ยท JSON Placeholder ยท https://jsonplaceholder.typicode.com/posts ยท
๐ŸŒ
JSONPlaceholder
jsonplaceholder.org โ€บ home
JSONPlaceholder | JSON Placeholder - jsonplaceholder.org
April 9, 2023 - JSON Placeholder uses HTTP methods like POST, GET, PUT, PATCH, HEAD, and DELETE for interaction examples between clients and servers. While all these methods work, produce results, and are functional, the data is not permanently stored in JSONPlaceholder.
๐ŸŒ
GitHub
github.com โ€บ typicode โ€บ jsonplaceholder โ€บ blob โ€บ master โ€บ templates โ€บ GUIDE.md
jsonplaceholder/templates/GUIDE.md at master ยท typicode/jsonplaceholder
In other words, if you try to access a post using 101 as an id, you'll get a 404 error. fetch('https://jsonplaceholder.typicode.com/posts/1', { method: 'PUT', body: JSON.stringify({ id: 1, title: 'foo', body: 'bar', userId: 1 }), headers: { "Content-type": "application/json; charset=UTF-8" } }) .then(response => response.json()) .then(json => console.log(json)) // Output { id: 1, title: 'foo', body: 'bar', userId: 1 }
Author ย  typicode
Find elsewhere
๐ŸŒ
Inari
devhunt.org โ€บ blog โ€บ get-started-with-jsonplaceholder-api
Get Started with JSONPlaceholder API
September 16, 2025 - JSON Placeholder API is a free tool for developers. It gives you fake data to use when you're building and testing apps. This tool has pretend info like posts, comments, and user profiles that you can use.
๐ŸŒ
Beeceptor
app.beeceptor.com โ€บ mock-server โ€บ json-placeholder
JSONPlaceholder APIs - Mock API
There are a variety of endpoints available and each provides JSON response for resources such as posts, users, comments, todos, etc. The mock server generates realistic random data on every invocation. Note: Don't use trailing slashes, and match the path exactly as shown. JSONPlaceholder APIs is your solution to frontend-first development!
๐ŸŒ
ReqBin
reqbin.com โ€บ o0tzomnc
API request example to jsonplaceholder.typicode.com using the HTTP PUT method
An example of making an HTTP PUT request to the https://jsonplaceholder.typicode.com/posts/1 API endpoint.
๐ŸŒ
StackBlitz
stackblitz.com โ€บ edit โ€บ js-8tc4sw
JSONPlaceholder example - StackBlitz
JSONPlaceholder is a free online REST API that you can use whenever you need some fake data
๐ŸŒ
YouTube
youtube.com โ€บ watch
JSON Placeholder API Tutorial | For Beginners - YouTube
In this Json Placeholder API Tutorial, I will show step by step how to use start using the JSON Placeholder api!Chapters:0:00 Intro0:07 Demo of JSON Placehol...
Published ย  May 11, 2023
Views ย  6K
๐ŸŒ
Postman
postman.com โ€บ lunar-eclipse-220985 โ€บ jsonplaceholder โ€บ request โ€บ 7k2jsze โ€บ post-request
Post request | JSONPlaceholder
Accelerate API development with Postman's all-in-one platform. Streamline collaboration and simplify the API lifecycle for faster, better results. Learn more.
๐ŸŒ
Medium
medium.com โ€บ @funti009 โ€บ understanding-apis-using-jsonplaceholder-779b5405e35c
Understanding APIs using JSONplaceholder | by Charles | Medium
July 13, 2025 - JSONplaceholder is a simple and free fake API. It has different endpoints that give us fake posts, todos, comments etc.
๐ŸŒ
Jsonplaceholder
jsonplaceholder.ir
jsonplaceholder | RTL fake REST/GraphQL API for testing and prototyping.
RTL fake REST/GraphQL API for testing and prototyping, based on {JSON}Placeholder. ... Try GET, POST or other HTTP methods on /posts, /comments, /photos, /todos or /users.
๐ŸŒ
DummyJSON
dummyjson.com โ€บ docs โ€บ posts
Posts - DummyJSON - Free Fake REST API for Placeholder JSON Data
fetch('https://dummyjson.com/posts/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: 'I am in love with someone.', userId: 5, /* other post data */ }) }) .then(res => res.json()) .then(console.log); Show Output
๐ŸŒ
DummyJSON
dummyjson.com
DummyJSON - Free Fake REST API for Placeholder JSON Data
DummyJSON Server creates dynamic placeholders instantly, no more image hunting or complex setups. Just add the URL and you're good to go! ... Access real-life data, fully organized and ready to use, all in one place. ... Use the dropdown to get results for different resources. fetch(`https://dummyjson.com/ RESOURCE products carts users posts comments quotes recipes todos `) ... Need a REST API for custom JSON data?
๐ŸŒ
Codeomelet
codeomelet.com โ€บ posts โ€บ javascript-xhr-using-jsonplaceholder-api
Javascript Xhr Using Jsonplaceholder Api | CodeOmelet
The response from JSONPlaceholder for this POST request will be a JSON object which looks like shown below. The id in the response will always be 101 and no real object is created at the API's end, this is just a fake response we get from JSONPlaceholder REST API with the response HTTP status as 201.
๐ŸŒ
Jlstrater
jlstrater.github.io โ€บ spring-restdocs-public-api-example
Example API Guide for the JSON Placeholder API
A POST request will create new posts. $ curl 'http://jsonplaceholder.typicode.com/posts' -i -X POST -H 'Accept: */*' -H 'Content-Type: application/json; charset=UTF-8' -d '{"userId": 1, "id": 101, "title": "Test Example", "body": "Example Body"}'