JavaScript
OMDb API
youngseokim_kr
2021. 10. 25. 17:37
주소를 통해서 영화 정보를 요청
OMDb API - The Open Movie Database
www.omdbapi.com
Query String
주소?속성=값&속성=깂&속성=값 //주소를 입력할때 옵션을 입력
?apikey S= 영화제목
http://www.omdbapi.com/?apikey=7035c60c&s=frozen apikey 를 입력하고 s에 겨울왕국을 입력
이러한 창이 나온다.
axios 패키지
$ npm install axios 명령어로 설치
import axios from "axios"; //패키지 가져오기
function fetchMovies() {
axios
.get('https://www.omdbapi.com/?apikey=7035c60c&s=frozen') //주소복사하기 https로 적어줘야한다. 얻는다.
.then(res => {
console.log(res)
const h1El = document.querySelector('h1')
const imgEl = document.querySelector('img')
h1El.textContent = res.data.Search[0].Title
imgEl.src = res.data.Search[0].Poster
})
}
fetchMovies()