--- title: HTTP Challenge tags: description: description of "HTTP Challenge". --- # HTTP Challenge <br> ## 第三關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv3?token={5566NO1}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv3?token={5566NO1} ``` ### JavaScript ```javascript= const request = require('request') const BASE_URL = 'https://lidemy-http-challenge.herokuapp.com/api' request.post( { url: `${BASE_URL}/books`, form: { name: '《大腦喜歡這樣學》', ISBN: '9789863594475' } }, function (error, response, body) { const data = JSON.parse(body) console.log(data) } ) ``` ### 回傳訊息 ```javascript= https://lidemy-http-challenge.herokuapp.com/lv3?token={5566NO1}&id=1989 ``` <br> ## 第四關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv4?token={LEarnHOWtoLeArn}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv4?token={LEarnHOWtoLeArn} ``` ### JavaScript ```javascript= const request = require('request') const BASE_URL = 'https://lidemy-http-challenge.herokuapp.com/api' request( { url: `${BASE_URL}/books`, }, function (error, response, body) { const data = JSON.parse(body) for (let i=0; i< data.length; i++) { if (data[i].author === '村上春樹') { console.log(data[i].id + ' ' + data[i].name) } } } ) ``` ### 回傳訊息 ```javascript= https://lidemy-http-challenge.herokuapp.com/lv4?token={LEarnHOWtoLeArn}&id=79 ``` <br> ## 第五關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv5?token={HarukiMurakami}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv5?token={HarukiMurakami} ``` ### 題目說明 昨天有個人匆匆忙忙跑過來說他不小心捐錯書了,想要來問可不可以把書拿回去。 跟他溝通過後,我就把他捐過來的書還他了,所以現在要把這本書從系統裡面刪掉才行。 那本書的 id 是 23,你可以幫我刪掉嗎? ### JavaScript ```javascript= const request = require('request') const process = require('process') const BASE_URL = 'https://lidemy-http-challenge.herokuapp.com/api' const arg = process.argv[2] request( { method: 'DELETE', url: `${BASE_URL}/books/${arg}`, }, function (error, response, body) { const data = JSON.parse(body) console.log(data) } ) ``` ### 回傳訊息 ```javascript= {"message":"\n咦...是刪掉了沒錯,但總覺得哪裡怪怪的,算了,先這樣吧!下一關的 token 為 {CHICKENCUTLET}\n"} ``` <br> ## 第六關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv6?token={CHICKENCUTLET}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv6?token={CHICKENCUTLET} ``` ### 題目說明 我終於知道上次哪裡怪怪的了! 照理來說要進入系統應該要先登入才對,怎麼沒有登入就可以新增刪除... 這太奇怪了,我已經回報給那邊的工程師了,他們給了我一份新的文件:https://gist.github.com/aszx87410/1e5e5105c1c35197f55c485a88b0328a。 這邊是帳號密碼,你先登入試試看吧,可以呼叫一個 /me 的 endpoint,裡面會給你一個 email。 把 email 放在 query string 上面帶過來,我看看是不是對的。 帳號:admin 密碼:admin123 ### JavaScript ```javascript= const request = require('request') const BASE_URL = 'https://lidemy-http-challenge.herokuapp.com/api/v2' request( { method: 'GET', url: `${BASE_URL}/me`, headers: { 'Authorization': 'Basic YWRtaW46YWRtaW4xMjM=', } }, (error, response, body) => { const data = JSON.parse(body) console.log(data) } ) ``` ### 回傳訊息 ```javascript= { username: 'admin', email: 'lib@lidemy.com' } ``` ### email 放在 query string 上面帶過來 ```javascript= https://lidemy-http-challenge.herokuapp.com/lv6?token={CHICKENCUTLET}&email=lib@lidemy.com ``` <br> ## 第七關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv7?token={SECurityIsImPORTant}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv7?token={SECurityIsImPORTant} ``` ### 題目說明 那邊的工程師說系統整個修復完成了,剛好昨天我們發現有一本書被偷走了... 這本書我們已經買第五次了,每次都被偷走,看來這本書很熱門啊。 我們要把這本書從系統裡面刪掉,就拜託你了。 對了!記得要用新的系統喔,舊的已經完全廢棄不用了。 書的 id 是 89。 ### JavaScript ```javascript= const request = require('request') const process = require('process') // 這行可以不用寫 const BASE_URL = 'https://lidemy-http-challenge.herokuapp.com/api/v2' const arg = process.argv[2] request( { method: 'DELETE', url: `${BASE_URL}/books/${arg}`, headers: { 'Authorization': 'Basic YWRtaW46YWRtaW4xMjM=', } }, (error, response, body) => { const data = JSON.parse(body) console.log(data) } ) ``` ### 回傳訊息 ```javascript= { message: '\n希望下一次進這本書的時候不會再被偷走了。下一關的 token 為 {HsifnAerok}\n' } ``` <br> ## 第八關 ### [挑戰連結](https://lidemy-http-challenge.herokuapp.com/lv8?token={HsifnAerok}) ```javascript= https://lidemy-http-challenge.herokuapp.com/lv8?token={HsifnAerok} ``` ### 題目說明 我昨天在整理書籍的時候發現有一本書的 ISBN 編號跟系統內的對不上,仔細看了一下發現我當時輸入系統時 key 錯了。 哎呀,人老了就是這樣,老是會看錯。 那本書的名字裡面有個「我」,作者的名字是四個字,key 錯的 ISBN 最後一碼為 7,只要把最後一碼改成 3 就行了。 對了!記得要用新的系統喔,舊的已經完全廢棄不用了。 ### JavaScript ```javascript= ``` ### 回傳訊息 ```javascript= ``` <br> <!-- ## 第x關 ### [挑戰連結]() ```javascript= ``` ### 題目說明 ### JavaScript ```javascript= ``` ### 回傳訊息 ```javascript= ``` --> <br> ## 參考資源 - [Lidemy http challenge](https://lidemy-http-challenge.herokuapp.com/start) - [Lidemy http challenge 紀錄](https://dylan237.github.io/http-game.html) ###### tags: `程式導師實驗計畫第四期`, `week5` <style> .red { color:#eb4034 } </style>