Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

freeCodeCamp

.NET 5 REST API Tutorial - Build From Scratch With C#

via freeCodeCamp

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
Build a comprehensive REST API from scratch using .NET 5 and C# in this extensive 6-hour tutorial. Learn to create, implement, and test various API endpoints, including GET, POST, PUT, and DELETE operations. Explore key concepts such as dependency injection, data transfer objects (DTOs), and asynchronous programming. Dive into database integration with MongoDB, implement health checks, and secure your API. Gain hands-on experience with containerization using Docker and orchestration with Kubernetes. Master unit testing and test-driven development (TDD) techniques to ensure code quality and reliability. By the end of this tutorial, you'll have a solid foundation in building robust and scalable REST APIs using the latest .NET technologies.

Syllabus

Introduction.
Creating the project.
Exploring the generated project files.
Trusting the self-signed certificate.
Exploring the default Swagger UI page.
Configuring Visual Studio Code settings.
Introduction.
Adding an entity.
Ading an in-memory repository.
Creating the controller.
Implemeting GET all items.
Implemeting GET single item.
Returning a 404 NotFound status code.
Introduction.
What is dependency injection?.
Extracting the repository interface.
Injecting the repository into the controller.
Registering the repository as a singleton.
Adding a Data Transfer Object DTO.
Creating the AsDto extension method.
Introduction.
Implementing POST.
Adding validations via data annotations.
Implemeting PUT.
Implementing DELETE.
Introduction.
Using Postman.
Creating a MongoDB repository.
Using the MongoDB.Driver NuGet package.
Implementing MongoDB Create.
Running the MongoDB Docker container.
Configuring MongoDB connection settings.
Registering the MongoClient singleton.
Testing the MongoDB integration.
Exploring the created database in VS Code.
Implemeting MongoDB Get, Update and Delete.
Introduction.
Using the Async suffix.
Using tasks in the repository.
Using async and await.
Returning completed tasks.
Using tasks in the controller.
Testing async methods in Postman.
Introduction.
Enabling authentication in MongoDB.
Using the .NET Secret Manager.
Using the MongoDB credentials in the service.
Introduction to Health Checks.
Adding an endpoint for health checks.
Adding a MongoDB health check.
Adding checks for readiness and liveness.
Customizing the health check response.
Exploring other health check NuGet packages.
Introduction.
What is Docker?.
Removing https redirection.
Generating a Dockerfile in VS Code.
Building the Docker image.
Adding a Docker network.
Running the containers in the Docker network.
Running the REST API in Docker.
Pushing the container image to Docker Hub.
Exploring the image in Docker Hub.
Pulling the image back to the local box.
Introduction.
What is Kubernetes?.
Enabling a Kubernetes cluster in Docker Desktop.
Installing the Kubernetes extension for VS Code.
Declaring the REST API Kuberentes deployment.
Creating a secret in Kubernetes.
Declaring health probes.
Declaring the REST API Kubernetes service.
Creating the REST API resources in Kubernetes.
Declaring the MongoDB Kubernetes StatefulSet.
Declaring the MongoDB Kubernetes service.
Creating the MongoDB resources in Kubernetes.
Testing the REST API hosted in Kubernetes.
Exploring the Kubernetes self-healing capability.
Scaling Kubernetes pods.
Adding logs via ILogger.
Getting a new image version into Kubernetes.
Load balancing requests across pods.
Introduction.
What is unit testing?.
What is test driven development?.
Restructuring files and directories.
Creating the xUnit test project.
Building multiple projects in VS Code.
Adding NuGet packages for unit testing.
Testing GetItemAsync unexisting item.
Using the AAA pattern.
Stubbing dependencies via Moq.
Running tests in VS Code.
Using the .NET Core Test Explorer extension.
Testing GetItemAsync existing item.
Using FluentAssertions.
Testing GetItemsAsync.
Testing CreateItemAsync.
Testing UpdateItemAsync.
Testing DeleteItemAsync.
Refactoring and catching regressions.
Using TDD to test a yet to be created method.
Going back to green by fixing the failing test.
Testing the new controller method in Postman.

Taught by

freeCodeCamp.org

Reviews

Start your review of .NET 5 REST API Tutorial - Build From Scratch With C#

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.