axios๋ฅผ ์ฌ์ฉ ์ค์ด๊ณ localhost:3000/posts ์ ๊ฒ์ํ๋ ค๊ณ ํ๋๋ฐ ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
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);
});
}
}
์ด๋ด,
Request failed with status code 400
๋ ์์ฒญ์ด ์์ฑ๋์์ง๋ง ์๋ฒ๊ฐ HTTP ์ฝ๋ 400(์๋ชป๋ ์์ฒญ)์ผ๋ก ์๋ต์ ๋ฐํํ์์ ์๋ฏธํฉ๋๋ค.
Axios์์ ๋ฌธ์ ๊ฐ ์๋๋ผ ๊ทํ์ ์น ์๋ฒ์์ ๋ฌธ์ ๊ฐ ๋๋ ๊ฒ ๊ฐ์์ ์ด PR์ ๋ซ์ต๋๋ค.
๋น๋๊ธฐ ๋ก์ง์ โโ์ ์ฉํ ์ ์๋ ์ฌ์ฉ์ redux ์ฝํฌ (๋ฏธ๋ค์จ์ด)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๋ด,
Request failed with status code 400
๋ ์์ฒญ์ด ์์ฑ๋์์ง๋ง ์๋ฒ๊ฐ HTTP ์ฝ๋ 400(์๋ชป๋ ์์ฒญ)์ผ๋ก ์๋ต์ ๋ฐํํ์์ ์๋ฏธํฉ๋๋ค.