title: How to send data to spring boot method using FETCH API
body: <p>I am exploring fetch api and want to send some for date to a spring boot method, but it is throwing <code>400</code> error</p>
  
  <p>JS code</p>
  
  <pre><code>let fetchConfig = {
              method : params.method || 'GET',
              body : params.body
          };
          return fetch(_url,fetchConfig).then(function (response) {
              if (!response.ok) {
                  throw Error(response.statusText);
              }
              else {
                  return response.json();
              }
          }).then(function (data) {
              return data;
          }).catch(function (error) {
              return error;
          })
  </code></pre>
  
  <p>Spring boot method</p>
  
  <pre><code>@RequestMapping(value = "/validate",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
      public  @ResponseBody ValidateUserModel validateUser(@RequestParam("userName") String userName, @RequestParam("password") String pass){
          System.out.println("--- test");
          ValidateUserModel validateUserModel = new ValidateUserModel();
          validateUserModel.setUserName("Test");
          validateUserModel.setPassWord("Test 2");
          return  validateUserModel;
      }
  </code></pre>
  
  <p>This is how <code>fetchConfig</code> looks like</p>
  
  <pre><code>body:{userName: "awdaw", password: "awdawd"}
  method:"POST"
  password:"test"
  url:"test"
  userName:"awdaw"
  __proto__:Object
  </code></pre>
  
  <p>Preview of the values send from java class</p>
  
  <pre><code>error:"Bad Request"
  exception:"org.springframework.web.bind.MissingServletRequestParameterException"
  message:"Required String parameter 'userName' is not present"
  path:"/validate"
  status:400
  timestamp:1504771336175
  </code></pre>
  
  <p>The error says <code>Required String parameter 'userName' is not present</code> but the <code>fetchConfig</code> have the required key</p>