PROGRAMING/FULL STACK

[Front End - Back End] The Axios library

donghunl 2024. 3. 21. 06:12
반응형

지금까지 작업한 Front End 파트와 Back End 파트를 연결하도록 하겠습니다. 

 

(참고) VS Code에서 따로 작업한 코드를 한 IDE에서 볼려면 새로 open folder로 오픈하거나 터미널에서 부모 폴더로 이동해서 code . 으로 새로운 IDE를 불러주면 됩니다.

 

Client와 Server를 연결하기 위해 Axios library를 사용합니다. 

https://axios-http.com/docs/intro

 

Getting Started | Axios Docs

Getting Started Promise based HTTP client for the browser and node.js What is Axios? Axios is a promise-based HTTP Client for node.js and the browser. It is isomorphic (= it can run in the browser and nodejs with the same codebase). On the server-side it u

axios-http.com

Axios는 네트워크를 요청을 하는데 매우 인기있는 라이브러리이며 Front End 와 Back End 프로젝트에 설치할수 있으면 거의 모든 URL에 모든 유형의 요청을 하는데 사용할수 있습니다.

먼저 Front End에 Axios를 설치합니다. 명령어는 다음과 같습니다.

cd .\my-blog\
npm install axios

 

다음은 데이터를 요청하고 데이터를 받는 간단한 사용 코드입니다.

// how to reqeust and get response
const response = await axios.get('http://localhost:8000/api/articles/learn-react');
const data = response.data;
반응형