簡體   English   中英

AZURE REST API - Fast API as Azure App Service or Azure Function App with Http triggered functions as endpoints?

[英]AZURE REST API - Fast API as Azure App Service or Azure Function App with Http triggered functions as endpoints?

我正在討論在 Azure 上實施具有數據庫基本 CRUD 的 REST API 的更“正確”/更好的性能解決方案是什么:

  1. 創建一個快速 API 應用程序並將其簡單地部署在 Azure 應用程序服務上
  2. Create an Azure Function App that every endpoint is represented by an Azure Http trigger function (inside of the azure function app) - the code in the function will be the basic CRUD functionality of the endpoint written in python (has nothing to do with fast api - 基本上只使用 FastAPI 路由中的純代碼)。

兩者最終都將使用 Azure API 管理器進行包裝。

什么解決方案會有更好的響應時間?

無服務器會更有彈性嗎?

謝謝

如果函數使用 python 運行時,那么FastAPI是一個非常流行的替代方案。

我個人發現將 Azure 函數遷移到 FastAPI 應用服務非常順利且輕松。

上述兩者的區別:

  • Function 獨立更改:主要我們需要在 include 語句中導入 FastAPI 和 Status,CORS 中間件以避免 CORS 問題。
  • 在 Azure 功能中,將通過門戶啟用 CORS。

要獲取有關 Function 相關更改、返回語句、添加多個函數/端點等差異的更多信息,請訪問 本文

FastAPI躋身性能最高的Python web 框架之列,用於構建 API,並且越來越多地被使用。

不僅在每秒處理的查詢數量方面,而且在開發速度和其內置的數據驗證方面都是后端的理想選擇。

您需要考慮的其他一些方面,例如可擴展性、成本和易於開發。

  • 如果您在應用服務上使用 Fastapi,則需要自己配置擴展規則。 消費或保費計划的 azure function 將自動擴展。
  • 即使您不使用應用服務上的 Fastapi,它也會花錢。 但是消費計划的 azure function 只有在您使用它並且每月免費執行 100 萬次時才會花費,因此如果您的執行次數小於 1M,則成本基本上為零。
  • 由於 FastAPI 是一個 API 框架,因此它內置會更正
    發生錯誤時的響應,您只需處理您需要的任何事情。 對於 Azure function,您幾乎需要編寫所有代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM