1.新建一个WebApi
使用终端构建一个webapi
cd 自己想要建项目的路径下
#创建webApi项目,-o后面是输出文件夹名称
dotnet new webapi -f net6.0 -o TestApi
#进入项目目录
cd TestApi
当右下角弹出“C#扩展”的提示框时,直接选择yes
2.启动项目
在终端输入命令或者直接按F5,会出现两个https
若直接打开会发现找不到页面
同时输入链接:https://localhost:7126/weatherforecast ,浏览器中会返回一些json,如下图
2.生成并测试API
在VsCode中打开一个新的终端,输入命令:dotnet tool install -g Microsoft.dotnet-httprepl
若出现:Unable to find an OpenAPI description,解决方案是:dotnet dev-certs https --trust
输入命令链接:httprepl https://localhost:7126
查看可用的终结点,终端输入:ls
转到WeatherForecast
发送get请求,得到一连串的JSON