---
tags: 軟體工程師體驗營 - 2023
---
# 🏅 JS 任務 Day26 - axios post 練習
POST 請求通常運用在要新增資料時,
像是:新增貼文、或是使用者登入註冊時都會使用 POST 請求
在發送 POST 請求時通常會根據 API 文件來觀看需要夾帶什麼資料(request body):
```javascript=
// URL:發送請求網址
// data:發送資料
axios.post('URL', data)
.then(function(response) {
// 成功時回傳
console.log(response);
})
.catch(function (error) {
// 失敗時回傳
console.log(error);
})
```
## 題目
嘗試運用 axios 發送此 [API](https://reqres.in/) 中的 POST Register 請求:
`https://reqres.in/api/register`
<img src="https://hackmd.io/_uploads/BJdCERZ82.png" width="300">
發送時需帶入 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 連結貼至「回報區」回報
(也可以將答案直接貼至「回報區」)

<!-- 解答:
axios.post('https://reqres.in/api/register', {
email: "eve.holt@reqres.in",
password: "cityslicka"
})
.then(function(response) {
console.log('status: ', response.status);
console.log('id: ', response.data.id, ', token:', response.data.token);
})
.catch(function (error) {
console.log('status: ', error.response.status);
console.log('錯誤訊息: ', error.response.data.error);
})
-->
回報區
---
| 報數 | Discord 名字 | Codepen/其他回饋 |
|:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:|
| 1 | 翔.#0859 | [Codepen](https://codepen.io/energy95272z/pen/PoyrRMv?editors=0012) |
| 2 | Quantum#6093 | [Codepen](https://codepen.io/Min-Hao-Hung/pen/MWPMGpo) |
| 3 | Rochel#4754 | [Codepen](https://codepen.io/rochelwang1205/pen/yLRdjzX) |
| 4 | Tami#6742 | [Codepen](https://codepen.io/wqsdqbjn-the-vuer/pen/WNaqJXG) |
| 5 | Kulimusoda#2785 | [Codepen](https://codepen.io/yuch3n_chen/pen/MWPMGBO?editors=0011) |
| 6 | Snadra#1987 | [Codepen](https://codepen.io/mlqmhltg/pen/wvYLjNo) |
| 7 | JimWang#6134 | [Codepen](https://codepen.io/Jim-Wang-the-selector/pen/ZEqdoVx?editors=0011) |
| 8 | Jacky7035#9423 | [Codepen](https://codepen.io/adens123/pen/dygBKKX) |
| 9 | ChaosTu#9311 | [Codepen](https://codepen.io/torotu/pen/OJBewRw?editors=0012) |
| 10 | 鄭舜仁#6606 | [Codepen](https://codepen.io/randomno/pen/QWZXBOX) |
|11|PayRoom#8328|[CodePen](https://codepen.io/water38198/pen/poxXZYg)
| 12 | Eero#1147 | [Codepen](https://codepen.io/Eero-Chiao/pen/RwezJKR) |
| 13 | gahwa#3562 | [Codepen](https://codepen.io/gahwa17/pen/zYmVJJa) |
| 14 | 銀光菇#1692 | [Codepen](https://codepen.io/genesynthesis/pen/rNqEZKd) |
| 15 | jia yu#8896 | [Codepen](https://codepen.io/fjqxaznl-the-reactor/pen/yLRdQPL?editors=1111) |
| 16 | Berlin#7338 | [Codepen](https://codepen.io/3qberlin/pen/LYgKXJO?editors=1111) |
| 17 | 姜承#8204 | [Codepen](https://codepen.io/Troy0718/pen/eYPwXGp) |
| 18 | Akira#9996 | [Codepen](https://codepen.io/Akira-Chen/pen/dygBrVV) |
| 19| Jennifer Chuang#3937 | [Codepen](https://codepen.io/yujhen/pen/MWPMMyN) |
| 20| David0799#4415 | [Codepen](https://codepen.io/David0799/pen/ZEqgWMw?editors=0010) |
| 21| townyuan#2653 | [Codepen](https://codepen.io/townyuan/pen/rNqXeog) |
| 22 | snow#0255 | [Codepen](https://codepen.io/snow21723/pen/JjmgKVy) |
| 23 | yoyo#1003 | [Codepen](https://codepen.io/crpbugqy-the-typescripter/pen/jOegqMa) |
| 24 | HsuanTang#1349 | [Codepen](https://codepen.io/HsuanTang/pen/oNaKJRm) |
| 25 | SKey#9905 | [Codepen](https://codepen.io/Dale-Chien/pen/gOQYVoZ) |
| 26 | Janet#5784 | [Codepen](https://codepen.io/janetlinnn/pen/qBQBbgo?editors=1111) |
| 27 | Uli#1946 | [Codepen](https://codepen.io/uli1313/pen/poQoVvm) |
| 28 | liam9930#4129 | [Codepen](https://codepen.io/jgnjfvvt-the-lessful/pen/MWzYYyM) |
| 29 | JasonChang#7847 | [Codepen](https://codepen.io/jsonChangJava/pen/dyQoGQz) |
|30|肉個阿倫#7172|[Codepen](https://codepen.io/i9574385/pen/abQOwaM)|
|31|兔子#6746|[Codepen](https://codepen.io/CarrotDetector/pen/MWzaNOP)|
| 32 | Kaya#8857 | [Codepen](https://codepen.io/laron9486/pen/PoxZBwV) |
| 33 | FanJJ#8061 | [Codepen](https://codepen.io/yfchenn/pen/yLQBBQq?editors=1011) |
| 34 | PoWei#8484 | [Codepen](https://codepen.io/harrison-wei-lai/pen/LYXzVrW?editors=0012) |
| 35 | Ann Chou#0146 | [Codepen](https://codepen.io/annchou_illu/pen/dyQjxeM) |
| 36 | 小明#4408 | [Codepen](https://codepen.io/ujlylmbv-the-lessful/pen/eYQPMXE) |
| 37 | hoyiiiii | [Codepen](https://codepen.io/hoyii/pen/ByBjGgo?editors=1012) |