title: I am getting a `KeyError` when I receive a request to my API
body: <p>I am building a dictionary app with Flask where users can add new words, I am trying to request the word from the word input , I am having issues with the POST request, the error I am receiving on my terminal is this:</p>
  <pre><code>        line 50, in add_word                   
          word = req['word']                                                                          
          keyError:'word'
  </code></pre>
  <p>and this is how I wrote the code in my app.py file:</p>
  <pre class="lang-py prettyprint-override"><code>@app.route('/word', methods= ['POST'])
  def add_word():
      req = request.get_json()
      word = req['word']
      meaning = req['meaning']
      conn = mysql.get_db()
      cur = conn.cursor()
      cur.execute('insert into word(word, meaning) VALUES (%s, %s)',(word, meaning))
      conn.commit()
      cur.close()
  
      return json.dumps(&quot;success&quot;)
  </code></pre>
  <p>here is the json in my JavaScript file, I am posting to my flask app:</p>
  <pre><code>     $('#word-form').submit(function() {
      let word = $('word').val();
      let meaning = $('meaning').val();
      
  
      $.ajax({
          url: '/word',
          type: 'POST',
          dataType: 'json',
          data : JSON.stringify({
              'word': word,
              'meaning': meaning
          }),
          contentType: 'application/json, charset = UTF-8',
          success: function(data) {
              location.reload();
          },
          error: function(err) {
              console.log(err);
          }
      })
  </code></pre>
  <p>here is the Html page:</p>
  <pre><code>    &lt;div class=&quot;div col-md-2 sidenav&quot;&gt;
      &lt;a href=&quot;#&quot; id=&quot;word-index&quot; class=&quot;side-active&quot;&gt;All words&lt;/a&gt;
      &lt;a href=&quot;#&quot; id=&quot;word-add&quot;&gt;Add New&lt;/a&gt;
      &lt;div&gt;
          &lt;form action=&quot;javascript:0&quot; id=&quot;word-form&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label for=&quot;word&quot;&gt;Word:&lt;/label&gt;
                  &lt;input type=&quot;text&quot; 
                  class=&quot;form-control&quot; 
                  name=&quot;word&quot;
                  id=&quot;word&quot;
                  placeholder=&quot;Type in the word here:&quot;
                  required&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label for=&quot;Meaning&quot;&gt;Meaning:&lt;/label&gt;
                  &lt;textarea class=&quot;form-control&quot; id=&quot;meaning&quot; 
                   placeholder=&quot;enter the meaning here: &quot; required&gt;&lt;/textarea&gt; 
              &lt;/div&gt;
              &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-block btn-lg&quot; id=&quot;submit&quot;&gt;Submit&lt;/button&gt;
              &lt;button type=&quot;button&quot; class=&quot;btn btn-warning btn-block btn-lg&quot; id=&quot;cancel&quot;&gt;Cancel&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;div col-md-10 main&quot;&gt;
      &lt;table style=&quot;border: 2px;&quot;&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;SN&lt;/th&gt;
                  &lt;th&gt;Word&lt;/th&gt;
                  &lt;th&gt;Meaning&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody&gt;
              {% for word in words %}
              &lt;tr&gt;
                  &lt;td&gt;{{ loop.index }}&lt;/td&gt;
                  &lt;td&gt;{{ word['word'] }}&lt;/td&gt;
                  &lt;td&gt;{{ word['meaning'] }}&lt;/td&gt;
                  &lt;td&gt;&lt;button class=&quot;btn btn-sm btn-success btn-block edit&quot; id=&quot;{{word['id']}}&quot;&gt;Edit&lt;/button&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;button class=&quot;btn btn-sm btn-danger btn-block delete&quot; id=&quot;{{word['id']}}&quot;&gt;Delete&lt;/button&gt;&lt;/td&gt;
              &lt;/tr&gt;
              {% else %}
              &lt;tr&gt;
                   &lt;td colspan=&quot;3&quot;&gt;The dictionary has no words at the moment, please come bay later&lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>