코드예시를 통해 fetch와 axios의 차이점을 살펴본다.
const API_URL = "https://yts.mx/api/v2/list_movies.json"
//API control
export const checkmovie = () =>
//Can get whole data by async operation
fetch(API_URL)
.then(res => res.json())
.then(json => json.data.movies)
//axios
const option ={
url ='http://localhost3000/test`
method:'POST',
header:{
'Accept':'application/json',
'Content-Type':'application/json';charset=UTP-8'
},
data:{
name:'sewon',
age:20
}
axios(options)
.then(response => console.log(response))
export const seemovie = async () => {
const movies = await axios.get('https://yts.mx/api/v2/list_movies.json')
console.log(movies)
}
//seemovie by axios
export const seemovie = async (id) => {
//const movies = await axios.get('https://yts.mx/api/v2/list_movies.json')
//console.log(movies)
const{
data:{
data: {movies}
}
//data params (by then or callback)
}
//seemovie by axios
export const seemovie = async (id) => {
//const movies = await axios.get('https://yts.mx/api/v2/list_movies.json')
//console.log(movies)
const{
data:{
data: {movies}
}
//data params (by then or callback)
}
//ajax
= await axios('https://yts.mx/api/v2/list_movies.json', {
params: {
movie_id : id
}
})
return movies
}
https://velog.io/@shin6403/React-axios%EB%9E%80-feat.-Fetch-API
https://sigcho.tistory.com/126