I send http post from my react app to API like this :
const request = new Request('http://localhost:9000/login', {
method: 'POST',
headers: new Headers({"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}),
body: JSON.stringify({ username: username,
password: password})
})
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(({ token }) => {
localStorage.setItem('token', token)
});
And I debug it in console on my rails app, and this is the output :
<ActionController::Parameters {"{\"username\":\"qqqqqq\",\"password\":\"ssssss\"}"=>nil, "controller"=>"sessions", "action"=>"create"} permitted: false>
How do I parsing the params above, I need get username & password params ?