API Application Programming Interface 應用程式介面

Web API web application 透過網路運作來收發API。

CDN Content Delivery Network 內容派送服務網路。

ES6 Promise語法

串接第三方API

  • 需使用發送請求的工具 axios函式庫

    • Axios: Promise based HTTP client for the browser and node.js
    • 載入axios函式庫(官網) => <head>加入 axios CDN 或 install axios npm

語法

axios.get('URL') //用 axios.get (HTTP制定的標準中使用GET發出請求,閱讀資料。)
    .then(function(response) { //成功取得資料後,要執行的動作。
        //handle success
        console.log(response) //回傳的response是物件,可看物件內資料結構
     })
     .catch(function(error) { //失敗取得資料後,要執行的動作。
         //handle error
         console.log(error)
     )}
     .finally(function() {  //全部處理完後,永遠執行的動作。
         //always executed
     })

API axios with DOM event
歌詞API網站


#API #Axios #Promise #.then #.catch #HTTP GET #DOM Event







Related Posts

Day 164

Day 164

Vim Editor Notes

Vim Editor Notes

利用Google Apps Script串接行事曆發送Line Notify

利用Google Apps Script串接行事曆發送Line Notify


Comments