Try   HackMD

🏅 JS 任務 Day26 - axios post 練習

POST 請求通常運用在要新增資料時,
像是:新增貼文、或是使用者登入註冊時都會使用 POST 請求

在發送 POST 請求時通常會根據 API 文件來觀看需要夾帶什麼資料(request body):

// URL:發送請求網址 // data:發送資料 axios.post('URL', data) .then(function(response) { // 成功時回傳 console.log(response); }) .catch(function (error) { // 失敗時回傳 console.log(error); })

題目

嘗試運用 axios 發送此 API 中的 POST Register 請求:
https://reqres.in/api/register

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

發送時需帶入 email 與 password 資料:

{
  email: "eve.holt@reqres.in",
  password: "cityslicka"
}

請求成功時使用 console.log 印出以下資訊:

  • status
  • id, token

請求失敗時使用 console.log 印出以下資訊:

  • status
  • 錯誤訊息
    未帶入密碼時呈現 Missing password

由於此 API 主要是提供給開發者練習的假資料,所以 POST Register 帶入的信箱需為已經定義好的資料才會成功,另外請求成功時也不會真的新增資料

回報流程

  1. 將答案貼在 Codepen 並複製 Codepen 連結貼至「回報區」回報
    (也可以將答案直接貼至「回報區」)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

回報區

報數 Discord 名字 Codepen/其他回饋
1 翔.#0859 Codepen
2 Quantum#6093 Codepen
3 Rochel#4754 Codepen
4 Tami#6742 Codepen
5 Kulimusoda#2785 Codepen
6 Snadra#1987 Codepen
7 JimWang#6134 Codepen
8 Jacky7035#9423 Codepen
9 ChaosTu#9311 Codepen
10 鄭舜仁#6606 Codepen
11 PayRoom#8328 CodePen
12 Eero#1147 Codepen
13 gahwa#3562 Codepen
14 銀光菇#1692 Codepen
15 jia yu#8896 Codepen
16 Berlin#7338 Codepen
17 姜承#8204 Codepen
18 Akira#9996 Codepen
19 Jennifer Chuang#3937 Codepen
20 David0799#4415 Codepen
21 townyuan#2653 Codepen
22 snow#0255 Codepen
23 yoyo#1003 Codepen
24 HsuanTang#1349 Codepen
25 SKey#9905 Codepen
26 Janet#5784 Codepen
27 Uli#1946 Codepen
28 liam9930#4129 Codepen
29 JasonChang#7847 Codepen
30 肉個阿倫#7172 Codepen
31 兔子#6746 Codepen
32 Kaya#8857 Codepen
33 FanJJ#8061 Codepen
34 PoWei#8484 Codepen
35 Ann Chou#0146 Codepen
36 小明#4408 Codepen
37 hoyiiiii Codepen