This is my learning project for exploring REST APIs, SQL Server, and C#, and hosting it all in containers.
Prerequisites:
- Docker Desktop installed and running
- Project root contains Dockerfile and docker-compose.yaml
Commands (run in project root):
# Build images
docker compose build
# Start containers in background
docker compose up -d
# See running services and ports
docker compose ps
# Tail logs (choose a service: api | db | frontend)
docker compose logs -f apiDefault URLs (check with docker compose ps if you changed ports):
- Frontend: http://localhost:8080
- API (Swagger): http://localhost:5000/swagger
- SQL Server: localhost,1433 (inside cluster use host: db)
Stop and clean up:
# Stop and remove containers, network (keeps DB volume)
docker compose down
# Optional: remove persisted DB data volume to start fresh
docker volume rm restapi_sql_dataNotes:
- If Docker warns that
versionin docker-compose.yaml is obsolete, remove theversion:line. - API listens on port 8080 inside the container; docker-compose publishes it to your host (5000 by default in this project).
- Connection string is injected via environment variables in docker-compose.
dotnet restore src/RestApi.csproj
dotnet build src/RestApi.csproj
dotnet run --project src/RestApi.csprojOpen http://localhost:5000/swagger.
See the Database section below if you prefer running SQL Server outside Docker.
- Register an OAuth app on GitHub.
- Copy secrets into the
secrets/folder (not committed). - Ensure your callback URL matches your environment/ports.
- GET /MyTable
- GET /MyTable/title?title=...
- GET /MyTable/director?director=...
On the server:
# Install Docker/Compose (Ubuntu)
sudo apt update
sudo apt install -y docker.io docker-compose
sudo systemctl enable --now docker
# Copy project to server, then in project root:
sudo docker compose up -d
sudo docker compose psConnects to a SQL Server database and exposes the data as a JSON API. The current code uses the provided .csv and .sql script with the database hosted locally by an SQL manager, but the code can easily be changed to run with other databases. You can query titles, directors, cast, descriptions and so on through the frontend — if it's in the table and has a controller, it's accessible.
git clone [URL]
dotnet restore
dotnet runOpen your browser at http://localhost:5000/swagger for interactive docs.
-
Create the database:
- Open SSMS (or your preferred SQL client).
- Right-click "Databases" > "New Database..." and name it
csvNetflixDB. - Click OK to create the database.
-
Create the table:
- Select the new
csvNetflixDBdatabase. - Open the provided
CreateTable.sqlscript in theDatabase/SQLscripts/folder. - Run the script to create the
NetflixDatasettable.
- Select the new
-
Import the CSV data:
- In SSMS, right-click the
csvNetflixDBdatabase and choose "Tasks" > "Import Data". - Select the
Netflix Dataset.csvfile as the source from theDatabase/folder in this project. - Map columns as needed and complete the wizard.
Alternatively, use a
BULK INSERTcommand:BULK INSERT dbo.NetflixDataset FROM 'C:\Path\To\Netflix Dataset.csv' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', TEXTQUALIFIER = '"' );
- In SSMS, right-click the
Note: If your SQL Server instance name or authentication differs, update the connection string in
appsettings.jsonaccordingly.
Start the backend API by running:
dotnet restore src/RestApi.csproj
dotnet build src/RestApi.csproj
dotnet run --project src/RestApi.csprojin the integrated terminal.
Then, open frontend/index.html in your browser.
Use the search forms to query the database by title, director, or cast.
Results will be displayed on the page in JSON format.
Make sure the backend is running before using the frontend.
- Register your own GitHub OAuth app at https://github.com/settings/developers.
- Rename the
TEMPLATE secrets/-folder tosecrets/. The program is configured with the path of that folder. - Fill in your own Client ID and Client Secret in secrets.txt.
- Make sure
secret.txtis not committed to git. The .gitignore is part of the repository, so by default it will not be committed. - Either make sure that Live Server or the extension you are using listens to port 5504, or change to a port of choice in the code.
GET /MyTable— All data, all at once.GET /MyTable/title?title=Stranger Things— Find a show by title.GET /MyTable/director?director=John Doe— Search by director.- More endpoints? Add them in
src/Controllers/MyTableController.cs.
- .NET 9 SDK
- The database itself (.csv and .sql-script to import it is included in the repository)
- A program to host the SQL DataBase locally, like Microsoft SQL Server Management Studio (SSMS) or PostgreSQL
- I use VScode as the IDE to build the project. If you are inexperienced, I recommend you using the same if you want to clone the repo.
These are automatically restored from the project file, but for reference:
Microsoft.AspNetCore.OpenApiMicrosoft.EntityFrameworkCore.SqlServerSwashbuckle.AspNetCore
- C# Dev Kit (for C# language support and debugging)
- C# (by Microsoft)
- SQL Server (mssql) (for connecting to and managing SQL Server databases)
- REST Client (for testing API endpoints directly in VS Code)
- .NET Install Tool for Extension Authors (helps with .NET SDK management)
Open a pull request, file an issue, or fork away.
This API is built to be extended, and not only by me.
I will be very happy if I see forks with comments to help me learn and improve as a developer.