REST APIでiwb.jpの投稿一覧のtitleを20件表示するサンプル

// <ul id="r"></ul>
fetch('https://iwb.jp/wp-json/wp/v2/posts?per_page=20')
  .then(response => response.json())
  .then(data => {
    const r = document.getElementById('r')
    const html = data.reduce((a, c) => {
      a.push(c.title.rendered)
      return a
    }, [])
    r.innerHTML = '<li>' + html.join('</li><li>') + '</li>'
  });

元記事を表示する