ASP. NET Core WebAPI Development-New WebAPI project,
The ASP. NET Core 1.0 RC2 is about to be released, so let's learn about ASP. NET core WEBAPI development.
There are already leaked VS2015 tooling on the internet and need to VS2015 Update 2.
. NET Core 1.0.0 RC2 SDK Preview1 Win64 http://download.microsoft.com/download/2/1/0/ 2107669a-0df9-4a91-a275-74735d433045/dotnet-dev-win-x64.1.0.0-preview1-002702.zip
Winsvr Hosting https://download.microsoft.com/download/4/6/1/46116DFF-29F9-4FF8-94BF-F9BE05BE263B/ Dotnetcore.1.0.0.rc2-windowshosting.exe
VS2015 Tooling https://download.microsoft.com/download/4/6/1/46116DFF-29F9-4FF8-94BF-F9BE05BE263B/ Dotnetcore.1.0.0.rc2-vs2015tools.preview1.exe
I also installed the first time, finally can use vs development. NET Core applications.
After installing VS2015 tooling, we can select. NET Core in the new project.
New WEBAPI Project
New Project
This is the new WEBAPI project.
The ASP. NET Core application runs, you can choose IIS Express or you can choose to run it yourself, the server is Kestrel.
Here we use the second kind of Kestrel.
The F5 program is also running, and VS will automatically open the browser.
Sometimes the browser will open, but not accessible, because the program has not yet run up, to the program to run a refresh.
Add API
In the Controllers folder, right-click Add-New item to select the WEB API controller class.
We add a userscontroller
[Route ("Api/[controller]")] Public classUserscontroller:controller {//get:api/values[HttpGet] Publicienumerable<string>Get () {return New string[] {"Linezero","Cnblogs" }; } //GET API/VALUES/5[HttpGet ("{ID}")] Public stringGet (intID) {return$"Linezero-{id}"; } }
View Code
The route here is written directly in the controller.
[Route ("Api/[controller]")]
Program run up access: http://localhost:5000/api/users
Http://localhost:5000/api/users/1
Developing an ASP. NET Core application, or vs good. Before with vs Code always some do not adapt.
Next: ASP. NET Core WebAPI Development-Entityframeworkcore
If you think this article is helpful to you, please click on the "
Recommended", thank you.
ASP. NET Core WebAPI Development-New WebAPI Project