iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 10
0
Microsoft Azure

Azure 的奇幻之旅系列 第 10

Azure 系列文(10) - Azure Functions 部署API

  • 分享至 

  • twitterImage
  •  

我們在做後端開發的時候,常常會有需要開API的時候,或者是有些單頁式應用不想要在自己的平台上管,這時候就可以選擇Azur Functions來做開發!並且支持了多種語言、Oauth,所以在做Web開發的時候,Azure Functions也不妨是個好選擇!

準備

  • Azure 帳號

部署一隻Python的API吧!

其實Azure Functions支援的語言有

  • C#
  • Java
  • JavaScript
  • PowerShell
  • Python
  • TypeScript

這篇主要拿Python來做示範

首先呢,第一步到Azure Portal,搜尋"函數應用程式",並且新增應用程式,接著填一些參數
https://ithelp.ithome.com.tw/upload/images/20200919/20127994nANEA7bnG1.png

接著填裝載中的地方
https://ithelp.ithome.com.tw/upload/images/20200919/20127994XiJV0Qbzmq.png

再來是監視的部分,這裡我把Application Insight關掉了,因為本篇不會介紹到,但後續的章節會介紹到~
https://ithelp.ithome.com.tw/upload/images/20200919/20127994NFQzh9twXs.png

按下建立就完成了!
https://ithelp.ithome.com.tw/upload/images/20200919/201279949NHSjXjfJZ.png

本地開發Azure Functions

再來我們可以到函式這邊點選於本機開發就可以在本機透過Vscode做開發了!
https://ithelp.ithome.com.tw/upload/images/20200919/20127994AAgN2SnD8y.png

再來我們到VScode安裝Azure functions的extension
https://ithelp.ithome.com.tw/upload/images/20200919/20127994JsCrTMMvPZ.png

接著按資料夾的圖案就可以Create Project了
https://ithelp.ithome.com.tw/upload/images/20200919/20127994al0yXIUzTp.png

再來選擇你的專案資料夾
https://ithelp.ithome.com.tw/upload/images/20200919/20127994Nk6RonNdPr.png

選擇你要使用的語言
https://ithelp.ithome.com.tw/upload/images/20200919/20127994MtDYl0FifH.png

再來選function的template,這邊選Http trigger
https://ithelp.ithome.com.tw/upload/images/20200919/20127994smm3IlHzro.png

Authorization level選擇Function
https://ithelp.ithome.com.tw/upload/images/20200919/201279940v6S1JNrd3.png

經歷這麼長的步驟,終於完成Create Project!!
https://ithelp.ithome.com.tw/upload/images/20200919/2012799434JxUUgRVs.png

再來這邊其實MS已經幫你把範例寫上去了,所以我們只要按執行測試看看就好了~
https://ithelp.ithome.com.tw/upload/images/20200919/20127994txAOEMhDb9.png

再來在網址列輸出,就可以看到API已經成功了!

http://localhost:7071/api/HttpTrigger1?name=jesper

https://ithelp.ithome.com.tw/upload/images/20200919/20127994eJYgs4xO3L.png

部署至Azure Functions

之後我們如果開發完畢的話,可以把我們的Functions推上Azure Functions,只要在VScode點選上傳的按鈕就可以部署上Azure Functions了,是不是很簡單!
https://ithelp.ithome.com.tw/upload/images/20200919/20127994WljfTkZ53u.png

之後就可以透過Azure functions的URL執行你的API了!!
https://ithelp.ithome.com.tw/upload/images/20200919/20127994dCwBTBnOE0.png


上一篇
Azure 系列文(9) - 幫你的Azure Kubernetes Service加上Https
下一篇
Azure 系列文(11) - Application Insight監視你的應用程式!
系列文
Azure 的奇幻之旅30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言