🌎
Go! Raymond
LinkedinGithub
  • 🤚Welcome!
  • 👨‍💻About Me
  • 🗒️Blog
    • Not just a technical blog
    • First Working Day After Leaving Trading Floor
  • 🇻🇳Work/Life in Saigon
    • Life in Saigon
      • 🪙胡志明市最佳換匯場所
      • 🥜五郡安東市場 | 伴手禮堅果類
      • 💸越南什麼東西便宜?
      • ☕胡志明工作咖啡廳
    • VN Market
      • 📒Vietnam Stock Market 101
      • 📈Major Equity Index
      • Market Research
        • 越南盾VND長期貶勢
  • 💻Technology
    • Data
      • Business Intelligence Platform
        • 📈Streamlit
          • Install and Create a Streamlit Project
      • 💾Storage | Database
        • How to install MySQL on your computer with Docker?
    • Docker
      • Docker Basic
    • Python
      • Speed up Python
        • Asynchronous
      • Clean Code in Python
        • 命名(Naming)
        • 寫法
    • Web Development
      • FastAPI
        • 建立API
        • 回傳HTML
      • RESTful API是什麼?
    • Office Automation
      • Word Template with Python
    • Task Automation
      • Rocketry
        • Example of historical stock price update (Rocketry)
      • Prefect
    • 💻How to build your own VPN server?
  • 🚀Startup
    • Y Combinator - Startup School
      • Should You Start A Startup?
  • 🌎Travel
    • 🏔️Himalaya, Nepal
      • 🗒️How to apply Nepal travel visa as Taiwanese?
      • 🏔️Annapurna Circuit Trek (ACT)
        • 🎒Equipments checklist
Powered by GitBook
On this page
  • RESTful API的URI命名規則
  • RESTful API安全性
  1. Technology
  2. Web Development

RESTful API是什麼?

RESTful API是一種API設計的風格,REST為Representational State Transfer的簡稱,RESTful API則代表符合此風格的API設計。

如果你沒有學過RESTful API模式,你隨便用Flask或FastAPI建立的API可能長這樣子,所有的方法都是使用GET ,在後端才針對不同的目的做出不同的命令。

目的
URL
Request Method

取得資料

http://127.0.0.1:8000/get-data/1

GET

新增資料

http://127.0.0.1:8000/insert-data/2

GET

更新資料

http://127.0.0.1:8000/update-data/3?value=5

GET

刪除資料

http://127.0.0.1:8000/delete-data/4

GET

如果你學會了RESTful API後,就會變成以下這樣,主要就是將執行的動作放在Request Method裡面。

目的
URL
Request Method

取得資料

http://127.0.0.1:8000/data/1

GET

新增資料

http://127.0.0.1:8000/data

POST

更新資料

http://127.0.0.1:8000/data/2

PUT

刪除資料

http://127.0.0.1:8000/data/3

DELETE

方法GET、POST、PUT與DELETE分別對應資料庫的CRUD。

RESTful API的URI命名規則

  • URI使用小寫

  • URI使用複數名詞

http://127.0.0.1:8000/products
[GET] /products 回傳所有產品
[GET] /products/1 回傳單筆產品
[POST] /products 新增產品
[PUT] /products/4 修改單筆產品
[DELETE] /products/5 刪除單筆產品

RESTful API安全性

在使用PUT 與DELETE 時代表修改資料庫的內容,此時必須加上權限驗證機制,例如使用token回傳,透過後端進行驗證。

Previous回傳HTMLNextOffice Automation

Last updated 1 year ago

💻