Axios는 웹 개발에서 널리 사용되는 HTTP 클라이언트 라이브러리이다.
Axios는 Promise기반으로 동작하기 때문에 간결한 비동기 코드 작성이 가능하다.
주요 특징을 알아보자
프로미스 기반
Axios 는 Promise를 반환하기 때문에 '.then()'과 'catch()'를 사용하여 비동기 처리를 할 수 있으며, 'async/await' 문법과 같이 사용하여 더욱 간결한 비동기 코드를 작성할 수 있다.
브라우저와 Node.js에서 동작
Axios는 브라우저 뿐만 아니라 Node.js 환경에서도 동작한다. 그러니, 클라이언트, 서버 양쪽 모두에서 사용가능하다.
요청과 응답의 변형
요청 전에 데이터를 수정하거나, 응답이 도착했을 때 데이터를 변형하는 것이 가능하다.
취소 가능한 요청
Axios는 요청을 취소하는 기능을 제공한다
응답시간 제한
특정 시간 이내에 응답이 오지 않으면 요청이 실패한 것으로 간주하는 시간 제한 기능을 제공한다.
JSON데이터 자동 변환
Axios는 기본적으로 JSON 데이터의 자동변환을 지원한다.
import axios from 'axios';
// GET 요청
axios.get('/api/data').then( response => {
console.log(response.data);
}).catch( error => {
console.log(`Error fetching data ${error}`);
});
// POST 요청
axios.post('/api/data, {
param1: 'value1',
param2: 'value2'
}).then( response => {
console.log(response.data);
}).catch( error => {
console.log(`Error sending data ${error}`;
});
import axios from 'axios';
async function fetchData(){
try{
const response = await axios.get('https://api.example.com/data');
console.log(`Data : ${response.data}`);
} catch(error){
console.log(`Error : ${error}`);
}
}
fetchData();
const instance = axios.create({
baseURL: 'https://api.example.com',
timeout: 1000,
headers: {'Authorization': 'Bearer my-token'}
});
instance.get('/data').then( response => {
console.log(response.data);
});
안녕하세요! 29기 운영진에 지원할려고 하는데 파트 크로스 스터디에 대한 정보를 여쭤보고 싶어 문의드립니다.
파트 크로스 스터디의 경우, 정기 교육 세션처럼 교육기획팀에서 강연을 하는 것일까요?
감사합니다.