title: I can not fetch a post in JavaScript
body: <p>I have a question about the code. Probably the solution is very simple, but I'm taking the first step in JavaScript and it is not obvious to me.</p>
  
  <p>I have some backend ready, postman sending POST is ok. So backend is fine.</p>
  
  <p>I wrote a simple application in which after pressing the button saves the given data in the database.</p>
  
  <p>Unfortunately, this doesn't work with the debugger, everything is fine. However, by clicking the button in the view something is wrong and no fetch is called. The object is not saving to the database.</p>
  
  <p>Please help.</p>
  
  <pre class="lang-js prettyprint-override"><code>Api = function() {
    this.header = new Headers({
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    })
  };
  
  Api.prototype.buildUrl = function(id) {
    return "http://localhost:3000/db/shop_name/" + id;
  };
  
  Api.prototype.post = function(id, data) {
  
    const urlPost = api.buildUrl(id.value);
    return fetch(urlPost, {
        method: "post",
        body: JSON.stringify(data),
        headers: this.header
      })
      .then(res =&gt; res.json())
      .then(res =&gt; {
        console.log("Dodałem użytkownika:");
        console.log(res);
      })
  };
  
  Api.prototype.get = function(id) {
    //const urlGet = api.buildUrl(id);
    return fetch(id, {
        method: "GET",
      })
      .then(resp =&gt; {
        alert(resp.json());
  
        return resp.json();
      })
  };
  Api.prototype.getAlll = function() {
    return fetch(url, {
        method: "GET"
      })
      .then(resp =&gt; {
        alert(resp.json());
        return resp.json()
      })
  };
  
  Api.prototype.update = function(id, data) {
    const url = api.buildUrl(id);
    return fetch(url, {
        method: "PUT",
        body: JSON.stringify(data)
      })
      .then(resp =&gt; {
        return resp.json()
          .catch(error =&gt; {
            let notFound = "The server can not find requested resource";
            document.getElementById("stars").innerHTML = notFound + error.status;
          })
      })
  };
  
  
  Api.prototype.addProduct = function(id, data) {
    return this.post(id, data);
  };
  
  Api.prototype.deleteProduct = function(id) {
    return this.delete(id);
  };
  
  Api.prototype.updateProduct = function(id, data) {
    return this.update(id, data);
  };
  
  Api.prototype.getProduct = function(id) {
    return this.get(id);
  };
  Api.prototype.getAllProducts = function() {
    return this.getAlll;
  };
  
  const Main = function() {
    this.id = document.getElementById("id");
    this.addCount = document.getElementById("count");
    this.addName = document.getElementById("name");
    this.addPrice = document.getElementById("price");
  };
  
  
  Main.prototype.add = function() {
    // const ido = this.id.value;
    const data = {
      "price": this.addPrice.value,
      "name": this.addName.value,
      "count": this.addCount.value,
    };
    //  let id = api.buildUrl(this.id.value);
    api.addProduct(this.id, data);
  };
  
  
  Main.prototype.update = function() {
    const data = {
      "price": this.price,
      "name": this.name,
      "count": this.count,
    };
    api.updateProduct(id, data);
  };
  
  Main.prototype.delete = function() {
    let id = api.buildUrl(this.id);
    api.deleteProduct(id);
  
  };
  
  
  Main.prototype.get = function() {
    let id = api.buildUrl(this.id.value);
    api.getProduct(id);
  
  };
  
  Main.prototype.getAll = function() {
    api.getAllProducts();
  
  };
  
  const api = new Api();
  const main = new Main();
  
  
  let addButton = document.getElementById('postBtn');
  addButton.addEventListener('click', function() {
    main.add();
  });
  
  /*
  addButton.addEventListener("click",main.add.bind(main));
  */
  
  
  let updateButton = document.getElementById("updateBtn");
  updateButton.addEventListener("click", function() {
    main.update();
  });
  
  
  let deleteButton = document.getElementById("deleteBtn");
  deleteButton.addEventListener("click", function() {
    main.delete();
  });
  
  let getButton = document.getElementById("getBtn");
  getButton.addEventListener("click", function() {
    main.get();
  });
  
  
  let getAllButton = document.getElementById("getAllBtn");
  getAllButton.addEventListener("click", function() {
    let tst = main.getAll();
    console.log(tst);
  
  });
  </code></pre>