iT邦幫忙

0

【Angular with .NET Core】建立後端環境

WM 2019-09-17 01:50:47396 瀏覽
  • 分享至 

  • xImage
  •  
  • 建立demo資料夾。
  • 在demo資料夾中分別建立backend與frontend資料夾。
  • 使用CMD在backend建立.NET Core新專案,命名DemoApp。
    https://ithelp.ithome.com.tw/upload/images/20190917/20112573wQlx21lfVI.png
  • 執行dotnet watch run,啟動專案。
  • https://ithelp.ithome.com.tw/upload/images/20190917/20112573bTnn3QTgum.png
  • 專案的網址有兩個:https://localhost:5001 與 http://localhost:5000
  • 網址有了,接下來是透過路由(Route)指定API取資料出來。
  • 開啟專案檔,DemoApp.csproj。
    https://ithelp.ithome.com.tw/upload/images/20190917/20112573GJyOaEgt1q.png
  • 在方案總管,開啟ValuesController.cs。
    https://ithelp.ithome.com.tw/upload/images/20190917/201125734V7hhWux3c.png
  • 專案的預設路由是api/[controller],[controller]表示這個class的名稱去掉controller字串。
    https://ithelp.ithome.com.tw/upload/images/20190917/20112573rbLY6pMRRX.png
  • 所以,第一隻API的路由即是api/values,HTTP Methods是GET。
  • API完整的路徑,是網址+路由,https://localhost:5001/api/values 。
  • 使用Postman取出資料。
  • 使用GET方法。
    https://ithelp.ithome.com.tw/upload/images/20190917/20112573kfooR5oD1L.png
  • 回傳成功,資料正確顯示,HTTP 狀態碼是200 OK。
    https://ithelp.ithome.com.tw/upload/images/20190917/20112573R5Nu0rc6FV.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言