[Javascript] 자바스크립트 Fetch함수로 백엔드와 통신하기
·
study/JavaScript🌟
개요 프론트엔드가 백엔드와 협업할 때, 자바스크립트 fetch함수를 쓰거나 axios를 사용하여 api를 호출할 수 있다. 설명 기본 구조는 다음과 같다. 1. api 주소를 써준다. 2. HTTP METHOD를 써준다. 이때, GET은 method를 따로 써주지 않아도 된다. 3. header, body가 있으면 써준다. 4. .then()으로 다음 로직을 써준다. fetch("api주소", { method: "POST", // HTTP Method(post, put, delete, get) headers: { "Content-Type": "application/json" }, body: JSON.stringify({name : cowboysj}) }) .then((response) => respons..