# Web Backend 1 ### ~~混亂的開始~~ --- ## 後端是甚麼? 能吃嗎? ![](https://hackmd.io/_uploads/B1gl5M-S3.png =50%x) ---- ## 後端主要用途 1. 資料處理與儲存 2. 業務邏輯處理 3. API設計和實作 4. 安全性和身份驗證 5. 伺服器管理和擴展性 --- # HTTP Method ---- <span style="font-size:25px"> | HTTP方法 | 描述 | | -------- | ----------------------------------------------------------------------- | | GET | GET 方法請求展示指定資源。使用 GET 的請求只應用於取得資料。 | | HEAD | HEAD 方法請求與 GET 方法相同的回應,但它沒有回應主體(response body)。 | | POST | POST 方法用於提交指定資源的實體,通常會改變伺服器資料的狀態。 | | PUT | PUT 方法會取代指定資源的請求。| | DELETE | DELETE 方法會刪除指定資源。| | CONNECT | CONNECT 方法會和指定資源標明的伺服器之間,建立隧道(tunnel)。| | OPTIONS | OPTIONS 方法會獲取目標伺服器支援的 HTTP 請求方法。| | TRACE | TRACE 方法會與指定目標伺服器執行迴路返回測試(loop-back test)。| | PATCH | PATCH 方法套用指定資源的部份修改。| </span> --- # HTTP Status Code ---- <span style="font-size:30px"> | 狀態碼 | 描述 | | ------ | --------------------------------------- | | 200 | OK - 請求成功 | | 201 | Created - 已成功建立新資源 | | 204 | No Content - 無回應內容 | | 400 | Bad Request - 請求無效 | | 401 | Unauthorized - 未經授權 | | 403 | Forbidden - 禁止存取 | | 404 | Not Found - 找不到資源 | | 500 | Internal Server Error - 伺服器內部錯誤 | | 502 | Bad Gateway - 錯誤的網關 | | 503 | Service Unavailable - 服務不可用 | </span> --- # 交換格式 ---- # XML ## 可延伸標記式語言 ---- ## XML Format ```xml= <category name=“Technology”> <book title=“Learning Amazon Web Services”, author=“Mark Wilkins”> <price>20 美元</price> </book> </category> ``` ---- # JSON ## JAVASCRIPT OBJECT NOTATION ---- ## JSON Format ![](https://hackmd.io/_uploads/By59lQbHn.png) ```json= { "crust": "original", "toppings": ["cheese", "pepperoni", "garlic"], "status": "cooking", "customer": { "name": "Brian", "phone": "573-111-1111" } } ``` ---- ## 玩看看 JSON [https://jsoneditoronline.org/](https://jsoneditoronline.org/) ---- ### XML vs JSON ![](https://hackmd.io/_uploads/rJOuxQ-r3.png) --- # API ### Application Programming Interface ---- {%youtube zvKadd9Cflc%} --- # RESTful API ---- ## 以取得文章作範例 | HTTP方法 | 路徑 | 描述 | | -------- | ------------------ | ---------------- | | GET | /api/articles | 取得所有文章列表 | | GET | /api/articles/{id} | 取得指定ID的文章 | | POST | /api/articles | 創建新文章 | | PUT | /api/articles/{id} | 更新指定ID的文章 | | DELETE | /api/articles/{id} | 刪除指定ID的文章 | --- # MVC 架構 ---- ![](https://hackmd.io/_uploads/B1xUhG-r2.png) --- # 結束啦~
{"metaMigratedAt":"2023-06-18T04:12:28.008Z","metaMigratedFrom":"YAML","title":"Web Backend 1","breaks":true,"contributors":"[{\"id\":\"63474674-1754-4936-9d31-80e84232b8c1\",\"add\":2811,\"del\":46}]"}
    92 views