title: How do I send user input through AJAX to Django REST API and return result after function API calculation?
body: <p>I want to learn creating RESTful API's and having AJAX communicating between the backend and frontend, and would like to do it using Python.</p>
  <p>I know Python pretty well but have troubles to understand the structure and flow of web applications and how F/E and B/E communicate with each other. Due to this, I would like my website to communicate with my backend RESTful API using AJAX (for educational purposes only.</p>
  <h2>My example application</h2>
  <p>With his in mind, I want to create a simple web application (website) that counts the number of occurrences of a word in a larger text area that users put in. The sequential use case will be:</p>
  <ol>
  <li>User (client) enters a word to be examined in a textfield: <em><strong>&quot;Hello&quot;</strong></em> <em>(input=&quot;text&quot;)</em></li>
  <li>User (client) enters one or many paragraphs to look
  into: <em><strong>&quot;Hello my name is Charles&quot;</strong></em> <em>(input=&quot;textarea&quot;)</em></li>
  <li>User (client) presses &quot;Submit&quot;-button</li>
  <li>User (client) receives an updated text (asynchronously) with the number of occurrences of his word in the entered paragraph(s): <em><strong>&quot;The word 'Hello' occurred 1 time in your text!&quot;</strong></em> <em>(asynchronously modified <p> tag)</em></li>
  </ol>
  <h2>My problem and questions</h2>
  <p>The website is done with two fields and one button. Now here's my problem:</p>
  <ul>
  <li><strong>How does the AJAX integration and workflow work?</strong> AJAX grab those inputs from the respective fields, send them
  to my REST API (that presumably have the function to count the
  words), and get a response back with the results, to then be shown to
  the user asynchronously?</li>
  <li><strong>Should I design my Django REST API with class-based views or function-based views?</strong> I really don't need a model to be saved to quickly return the number of occurrences of a word in the given text...</li>
  </ul>
  <p>I have my frontend ready from simple HTML5 and CSS3 templates. I can make it work using vanilla JavaScript. But I would like to learn the flow from having AJAX communicating between the F/E and B/E and also learn how to create RESTful API's using Python.</p>
  <p>Any help is appreciated! Sorry for the long post. Feel free to ask more if something's unsure of what I mean and I'll explain.</p>
  <p>Thanks a lot.</p>