서버란 데이터를 요청하면, 데이터를 가져다 주는 것이다.
규격에 맞게 요청을 해줘야 한다.
axios 사용
사용법은 익히 알고 있으니 생략한다.
get/post 사용법
실제 코드의 사용은 아래와 같다.
import axios from 'axios';
...
function App() {
...
<button
onClick={() => {
axios
.get('https://codingapple1.github.io/shop/data2.json')
.then(response => {
let data = response.data;
let cpShoes = [...shoes, ...data];
setShoes(cpShoes);
})
.catch(err => {
console.err(err);
});
}}
>
더보기
</button>
일단..
get을 두번 연속으로 해서
Promise.all([axios.get('/url'), axios.get('/url')])
위와 같이 사용가능하고
데이터를 보낼 때는
let data = {name: 'stu', code: '1'};
axios.post('url', data);