: 현재 가장 많이 사용되고 있는 자바스크립트 HTTP 클리이언트로, HTTP 요청을 Promise 기반으로 처리한다는 특징이 있다
//yarn
yarn add axios
//npm
npm install axios
쓰는 방식은 간단함!
API주소의 json 을 받아올 함수에 다음과 같이 적으면 된다.
const getMovie = () => {
axios.get(`https://yts.mx/api/v2/list_movies.json?minimum_rating=7.0&sort_by=year`)
.then(response => {
setMovie(response.data.movie);
setLoading(false);
})
}
노마드코더 리액트 영화 웹 서비스 코드를 참고 했다
참고로 다음 코드들도 다 적용됨!!
const getMovie = async() => {
const json = await (
await fetch(`https://yts.mx/api/v2/movie_details.json?movie_id=${id}`))
.json();
setMovie(json.data.movie);
setLoading(false);
}
const getMovie = () => {
const response = axios.get(`https://yts.mx/api/v2/movie_details.json?movie_id=${id}`);
setMovie(response.data.data.movie);
setLoading(false);
}
[React] styled-components (0) | 2022.06.15 |
---|---|
[React] React Router 사용하기 (0) | 2022.06.13 |
[React] 투두리스트 컴포넌트 구조 및 코드 분석 (0) | 2022.06.09 |
[React] Hooks: useMemo, useCallback, useRef (0) | 2022.06.05 |
[React] Hooks: useState, useEffect, useReducer (0) | 2022.05.31 |