I am using axios and trying to post to localhost:3000/posts and getting this error above. Here is the code:
import axios from 'axios';
import {
GET_ALL_POSTS,
GET_POST,
CREATE_POST,
DELETE_POST,
UPDATE_POST
} from './types';
const ROOT_URL = 'http://localhost:3000';
export function createPost({content, title}, cb) {
return function(dispatch) {
axios.post(`${ROOT_URL}/posts`, {content, title})
.then((response) => {
console.log(response);
dispatch({
type: CREATE_POST,
payload: response
});
})
.then(() => cb())
.catch((error) => {
if(error.response) {
console.log(error.response);
}
console.log("Problem submitting New Post", error);
});
}
}
Hey,
Request failed with status code 400
means that request was created, but server returned response with HTTP code 400 (Bad Request).
I'm closing this PR as it doesn't seem an issue in Axios but in your web server.
User redux thunk(Middleware) where you can apply asynchronous logics
Most helpful comment
Hey,
Request failed with status code 400
means that request was created, but server returned response with HTTP code 400 (Bad Request).