Axios 공식 홈페이지 따라하기

Axios 공식 홈페이지 따라하기 (3) - Axios API

vitamin3000 2025. 2. 5. 18:43

axios에 해당 config를 전송하면 요청이 가능하다

axios(config)

// POST 요청 전송
axios({
	method: 'post',
    url: '/user/12345',
    data: {
    	firstName: 'Fred',
        lastName: 'Flintstone'
    }
})

// node.js에서 GET 요청으로 원격 이미지 가져오기

axios({
	method: 'get',
    url: 'http://bit.ly/2mTM3nY',
    responseType: 'stream'
	})
    .then(function (response){
    	response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
    })

 

여기서 responseType: 'stream'에 집중하기 바란다.

이것은 대용량 파일을 한번에 로드하지않고 스트림으로 처리하여 메모리 효율성을 높인다

*스트림이란 ? 데이터를 작은 조각으로 나누어 순차적으로 처리하는 방식이다

 

요청 메소드 명령어

편의를 위해 지원하는 모든 요청 메소드의 명령어를 제공한다.

  • axios.requerst(config)
  • axios.get(url[,config])
  • axios.delete(url[,config])
  • axios.post(url[,data[,config])
  • axios.put(url[,data[,config]])
  • axios.patch(url[,data[,config]])

 

Axios 인스턴스

사용자 지정 config로 새로운 Axios 인스턴스를 만들 수 있다.

const instance = axios.create 또는 request, get, delete 등..