title: Python: FastAPI 422 Unprocessable Entity error
body: <p>When I use <code>GET</code> request to send data to the server it works fine, but when use <code>POST</code> request it throws &quot;422 Unprocessable Entity&quot; error.</p>
  <p>This is my Ajax request code:</p>
  <pre class="lang-js prettyprint-override"><code>var newName = &quot;Bhanuka&quot;; 
  //do your own request an handle the results
  $.ajax({
    type: &quot;post&quot;,
    url: &quot;/names/&quot;,
    data: {d:newName},
    dataType: 'json', 
    success: function(data){ 
       console.log(data);
    }
  });
  
  </code></pre>
  <p>and this is my FastAPI server side code:</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import FastAPI, Request,Body
  from pydantic import BaseModel
  
  from fastapi.templating import Jinja2Templates
  from fastapi.encoders import jsonable_encoder
  app = FastAPI()
  
  templates = Jinja2Templates(directory=&quot;templates&quot;)
  
  @app.get(&quot;/items/{id}&quot;)
  async def read_item(request: Request, id: str):
      return templates.TemplateResponse(&quot;item.html&quot;, {&quot;request&quot;: request, &quot;id&quot;: id})
  
  @app.post(&quot;/names/&quot;)
  async def create_item(d:str):
      return d
  
  @app.get(&quot;/items11/{item_id}&quot;)
  def read_item22(item_id: int, q: str ):
      return {&quot;item_id&quot;: item_id, &quot;q&quot;: q}
  </code></pre>