Query String, omdb api 연습

·2023년 1월 5일

JS

목록 보기
16/18

Query String

  • 문자를 갖고 검색
  • 주소?속성=값&속성=값&속성=값

omdb api
https://www.omdbapi.com/

axios
https://github.com/axios/axios

axios는 실제 브라우저에서 https를 처리해야 되기 때문에 npm i axios로 설치
npm i axios -D (개발 의존성 모드로 설치하면 안됨)

<body>
  <h1>Hello World!</h1>
  <img src="" alt="" width="200">

</body>
// Query String, 문자를 갖고 검색
// 주소?속성=값&속성=값&속성=값

import axios from 'axios'

function fetchMovies() {
  axios
  .get('https://www.omdbapi.com/?apikey=7035c60c&s=frozen')
  .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()

profile
기억하기 위해 기록하는 블로그 :)

0개의 댓글