This tutorial will focus on ASP.NET Core features, request pipeline, how to create an ASP.NET Core API and how to use an Entity Framework Core. We willl try to create an API with an ASP.NET Core and tries to establish the communication with the database to perform simple CRUD operations via an Entity Framework Core. The series will contain continuation articles to cover the topic in detail and we will end up having a functional Application.
PrerequisitesSince we start from the beginning, it is expected that the reader of this article/series is new to ASP.NET Core and does not really have the insights of what is it all about. Having said that, we will stick to our aim of starting and learning an ASP.NET Core from the scratch. We will use Visual Studio 2017 Enterprise edition for the entire series, but one can also use Visual Studio 2015 or the Community editions of Visual Studio. The best part about ASP.NET Core Applications is that they can also be developed with Visual Studio codes, which executes at OS X and Linux. To check the requests and response from the API, we will use a tool named Postman. It’s free and easy to use. Alternatively, one can use the tool of a choice for e.g. Fiddler.
RoadmapWe will follow a roadmap to learn and cover all the aspects of an ASP.NET Core in detail. Following is the roadmap or the list of articles, which we will cover in the entire series.

- Create API with ASP.Net Core (Day 1): Getting Started and ASP.NET Core Request Pipeline
- Create API with ASP.Net Core (Day 2): Create an API and return resources in ASP.NET Core
- Create API with ASP.Net Core (Day 3): Working with HTTP Status Codes and returning sub resources in ASP.NET Core API
- Create API with ASP.Net Core (Day 4): Working with Serializer Settings and Content Negotiation in ASP.NET Core API
- Create API with ASP.Net Core (Day 5): Understanding Resources in ASP.NET CORE API
- Create API with ASP.Net Core (Day 6): Inversion of Control and Dependency Injection in ASP.NET CORE API
- Create API with ASP.Net Core (Day 7): Getting Started with Entity Framework Core
- Create API with ASP.Net Core (Day 8): Entity Framework Core in ASP.NET CORE API
There is always a buzz with Microsoft to provide something like an open source, cross platform and more or less related to the mobility. Thus, in general ASP.NET Core is the answer to all that buzz. It is an open source framework with the cross platform capabilities, which could be leveraged to build Cloud based Applications, which are connected through the internet. One can develop any kind of Application like normal Web Applications, API or mobile based Applications. Its beauty of being an open source and cross platform, which enables a developer to also contribute to the code or customize the code available, as per the need or requirement and cross the platform barrier and develop the Applications for Windows, Mac as well as for Linux. Another interesting offering by an ASP.NET Core is that it can be run on full .NET framework or on only .NET Core. We know what .NET framework is, but what .NET Core is? In simple words, .NET Core is the modular version of .NET Framework or one can say that it is the subset of full .NET Framework.
“ASP.NET Core is a lean and composable framework for building web and cloud applications. ASP.NET Core is fully open source and available on GitHub. ASP.NET Core is available on Windows, Mac, and Linux.” from https://www.asp.net/core
We call it modular because it is released via NuGet in the assembly packages rather than one large assembly, which contains most of the core functionality. When we read about .NET Core, we also come across something called .NET Standard. .NET Standard is a standard , which specifies a common layering that a platform should support and .NET Core is the implementation did by Microsoft for the .NET Standard.
Installing ASP.NET CoreFor Visual Studio 2017, .NET Core Tools are included in the installer. One can find the installation guide at https://www.microsoft.com/net/core#windowsvs2017.

If someone uses Visual Studio 2015, installing .NET Core tools is not that tough, as one can download .NET Core SDK and tooling for Visual Studio. The current .NET Core version is 1.1 but that too depends upon when you are reading this article, so the version may be different, which depends on when one is reading this post. One can find all the installation related SDK, tooling and platform specific installers at
https://www.microsoft.com/net/download/core.

As soon as .NET Core is installed, one can start creating .NET Core projects. To verify that .NET Core is installed, open your Visual Studio, navigate to File-> New Project and one can see .NET Core project templates installed there.

Moving on to some hands on exercise, we will create a sample ASP.NET Core project, try to understand the project structure and other details. We will create a fresh ASP.NET Core Web Application from the scratch.
Open your Visual Studio, navigate to File -> New project; where you can see the available .NET CORE templates and filter for ASP.NET Core Web Applications, as shown below.
After filtering, we can see two options available in the templates, one saying to create ASP.NET Core Web Application using >NET Core and other says, using .NET Framework. We earlier discussed the difference between .NET Core Application and .NET Framework Application and also know that ASP.NET Core Web Application can be developed, using any of the two options depending upon our choice and need. We will choose .NET Core option as we just need to focus on this area and do not really require other capabilities of complete .NET Framework. We will try to create an API, which returns information of the employees. Therefore., we’ll name our API as EmployeeInfo.API and name the solution as EmployeeInfo, as shown below.

Click OK and we get the list of the templates, which we need to choose to create our Application. When we choose the template, the other dependent and additional files will be added to the project via NuGet.

Note that we can also choose the current ASP.NET Core version i.e. 1.1 or the earlier stable version as well, which was 1.0. Out of the three available templates, since we are in the process of creating an API, we can choose Web API template but that may again end up downloading unnecessary Nuget packages and default controller structure that we really do not require. The purpose of this article is to make .NET Core Application from the scratch to have better understanding and get better concept. To understand each and every thing, let’s start from the empty template, so that we have full control to add what exactly do we want. Thus, choose “Empty” and press OK button. NuGet Restore will download the required packages to support an empty template, which we choose and will we see that the created empty project contains some structure and the basic code, as shown beelow.
below

We got a solution named EmployeeInfo and a project named EmployeeInfo.API i.e. our ASP.NET Core project. There are two classes added i.e. Program.cs and Startup.cs. We can closely look into these classes and understand them.
Program.cs

Program.cs acts as a starting point of the Application like every other console Application in .NET. It contains the Main method as the starting point. Thus, we see that ASP.NET Core in general is a console Application that talks to ASP.NET specific components and the libraries. Application configuration and execution is the responsibility of Main method here. We know that to run a Web Application, it needs to be hosted and we also need to do that. If we lool closely into the Main method, we see that WebHostBuilder is initialized and since we host the Web Application, there is a need of Web Server now. The beauty of an ASP.NET Core is that it is decoupled from the environment, which the Web Server provides for hosting the Web Application. It is accompanied with two HTTP Servers, where the first is WebListener i.e. a Windows based Web Server and another is Kestrel i.e. a Web Server for cross platform Application hosting. Thus, the statement UseKestrel signifies Kestrel as the default. Since we are currently inside Visual Studio, so it will, by default use IIS Express as a default host. The statement UseIISIntegration specifies that IIS Express works as a reverse proxy Server for Kestrel. If there is a need to deploy an ASP.NET Core Application on the Windows Server, one should run IIS as a reverse proxy Server for Kestrel and if the Application has to be deployed on Linux, one should use a comparable reverse proxy Server like Apache to proxy requests to Kestrel.













Rajneesh GiriPosted Jul 28, 2017, 8:53 PM
Excellent article.. excellent explanation... thanks for sharing information.
Rafnas T PPosted May 10, 2017, 7:34 AM
Nice explanation about ASP.NET Core API. Thank you
Vignesh ManiPosted May 10, 2017, 6:01 AM
Nice Article Sir. Thank you for sharing.