I have server running on Spring and it has a rest method for GET
, here is what it looks like:
@GetMapping("/user")
ParentInOut getUsersOnly(@RequestBody ParentInOut clientSide)
{
return new ParentInOut(userRepository.findAll());
}
I'm trying to use axios
in my react.js application to get data:
let dumbJSON={
"messages":"",
"localDateTime":getValue(parameter)
};
const config = {
method: 'GET',
url: url,
body : dumbJSON,
headers: {
'Content-Type': 'application/json'
}
};
axios(config).then(function (res) {
console.log(res);
}).catch(function (err) {
console.log(err);
});
But it gives me error,saying Error: Request failed with status code 400 in web-console
And in spring console, I get Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: warning
How this can be resolved ?
I have also tried this :
var headers = {
'Content-Type': 'application/json'
};
axios
.get(url, dumbJSON, {headers})
.then(response => {
console.log(response);
})
.catch(erro => {
console.log(erro.response);
});
Gives me same error and warning but this time gets a response, which is the axios object itself with dumbJSON,headers,url etc.