Web API with ASP.NET and SQLITE — PART 1

Rashmi Milan
Nov 6 · 3 min read

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.

SQLite Database
SQLite Database
Web API — Displayed data fetched from SQLite Database using Entity Framework
Web API — Displayed data fetched from SQLite Database using Entity Framework

STEP 1: Create Project in Visual Studio

  1. Open Visual Studio (I used version 2019)
  2. Select “Create a New Project”
  3. Choose ASP.Net Core Web Application
Create ASP.Net Web API Project
Create ASP.Net Web API Project

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

Create ASP.Net Web API Project
Create ASP.Net Web API Project

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:

Create a new ASP.Net Web Application
Create a new ASP.Net Web Application

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

ASP.Net API Project Created
ASP.Net API Project Created

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

Check whether the project has been created successfully by launching IIS Server
Check whether the project has been created successfully by launching IIS Server
Default Web Page

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. :)

  1. Tools => NuGet Package Manager => Manage NuGet Packages for Solution
Tools => Nuget Package Manager => Manage NuGet Packages for Solution
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.

Choose MicrosoftEntityFramework
Choose MicrosoftEntityFramework

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.

Check whether the project has been created successfully by launching IIS Server
Check whether the project has been created successfully by launching IIS Server

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!

Next >>

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade