Web API with ASP.NET and SQLITE — PART 1

It is easy to build HTTP services using ASP.NET Web API framework. It is popular as it reaches browsers and mobile devices and is light-weight.
Let’s build a Web API using ASP.NET with data from SQLite Database.


STEP 1: Create Project in Visual Studio
- Open Visual Studio (I used version 2019)
- Select “Create a New Project”
- Choose ASP.Net Core Web Application

4. Select “Next” and fill in the Project Details Form as follows and click “Create”:

Note: The above details are customizable like Project Name, location of the Api and the Solution name to be stored on the system.
5. Finally, chose API section and click “Create” to generate a ASP.Net Core Web Application project as follows:

6. On successful creation of the project, the following will be displayed.

7. Press “CTRL + F5”. This should start the IIS Server and serve you a webpage as follows:

The api/values page is redirected due to a Controller “ValuesController.cs” file under Controllers folder. We will come to this section in detail later.
STEP 2: Setting Up Required Packages
As we will be accessing data from SQLite, we need a framework which support data access. For this purpose, we chose the Entity Framework Core. To install it as as a package, we need to choose “ Microsoft.EntityFrameworkCore” using NuGet, which is already available in Visual Studio 2019.
Note: Microsoft.EntityFrameworkCore.SQLite package should be sufficient for this project, however, there were few issues that came up. Do try with it, and do update me know if it worked. :)
- Tools => NuGet Package Manager => Manage NuGet Packages for Solution

2. Browse => provide Keyword as “Microsoft.EntityFrameWorkCore”
Choose the package and install the version 2.2.6. ass .NET target framework on my computer is of version 2.2 . If you have version 3.0 then you can try installing packages with latest stable 3.0 version.

Note: It is a good practice to press “CTRL + F5” after every change. If the default Webpage loads with “[“value1”,”value2"]” — then, we are going good.

So, then, let’s take a short break and then you can follow with PART 2 of creating the real API in action, wherein we fetch information from SQLite database.
Happy Coding!
