Node.js

[Node] Axios

JungCw 2024. 2. 28. 09:59

Axios는 클라이언트 사이드와 서버 사이드의 통신을 위한 HTTP 비동기 통신 라이브러리이다.

 

npm i axios

를 통해 설치할 수 있으며

import axios from 'axios';

import 문을 통해 세팅할 수 있다.

 

주로 사용하는 Method

 

1. GET

 

- 입력한 url이 존재하는 자원에 요청을 보낸다.

axios.get(url,[,config])

 

예시)

axios.get('http://localhost:8000/user/userinfo').then((response)=>{
    let info = response.data;
    console.log(info);
})

 

 

2. POST

 

- 새로운 리소스를 생성할 때 사용한다.

axios.post("url",{
	data객체
},[,config])

 

 

3. DELETE

 

- REST 기반 API 프로그램에서 데이터베이스에 저장되어 있는 내용을 삭제하는 목적으로 사용한다.

axios.delete(URL,[,config]);

 

 

4. PUT

 

- REST 기반 API 프로그램에서 데이터베이스에 저장되어 있는 내용을 갱신하는 목적으로 사용된다.

axios.put(url[, data[, config]])