title: How can I POST data from javascript to a c sharp back-end, and then receive it back?
body: <p>So, I am fairly new to C Sharp and I can't figure out how I can basically submit a POST request via javascript (in the front-end) using fetch, send it to a C Sharp back-end to process the data, and then receive it back to my site.</p>
  <p>My final goal is to achieve a search engine, where I can get user input from javascript and send it to my C Sharp back-end so I can crawl sites from a database and return the ones which contain the highest volume of the key-word.</p>
  <p>Here is what I am currently working within the front-end:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;./index.css&quot;&gt;
      &lt;title&gt;Search Engine&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form class=&quot;search&quot;&gt;
          &lt;h2&gt;Search Engine&lt;/h2&gt;
          &lt;input name=&quot;search&quot; type='text' placeholder='Search' /&gt;
          &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
      &lt;script&gt;
          const endpoint = &quot;file to send data to&quot;;
          const formEl = document.querySelector('form');
          formEl.addEventListener('submit', async(e) =&gt; {
              e.preventDefault();
              const formData = new FormData(formEl);
              const formDataSerialized = Object.fromEntries(formData);
  
              try {
                  const response = await fetch(url, {
                      method: 'POST',
                      body: JSON.stringify(formDataSerialized),
                      headers: {
                          'Content-Type': 'application/json'
                      }
                  });
                  const json = await response.json();
                  console.log(json);
              } catch(e) {
                  console.error(e);
                  alert('there was an error!');
              }
          })
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>As you can see, I have a basic form that submits a user search, however, the endpoint in my javascript function is currently empty, since I am not sending the data anywhere.</p>
  <p>I was looking around for a long while for a solution where I can make a web server with C Sharp and accept the data that way, however didn't find anything which I can use.
  Can anyone please help? I would appreciate it a lot.</p>