Earn More by Sharing What You Love
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!

Tim Corey
42m 43s
When working with web development today, one important tool is a sample Web API - something that you can use to test frontend web apps, mobile devices, or even software applications. In his detailed video on "Sample Data and Filtering - Building a Sample API in C#", Tim Corey walks us through creating a C# Web API that loads sample data from a JSON file, sets up filtering, and is prepared for deployment as a Docker container or a traditional web application.
In this article, we'll explore Tim's approach step-by-step, and explain the core concepts from ASP.NET Core Web API, Minimal APIs, and HTTP services.
Tim opens by explaining why creating a new Web API project is so important for developers. Whether you're building for mobile devices, a web app, or other software applications, having a lightweight sample API makes testing faster and smoother.
Tim states that by the end of the project, we will have:
This small project will enable developers to interact with HTTP services easily, through HTTP methods like GET, PUT, POST, and DELETE.
Tim begins by structuring the Web API project inside Visual Studio, the popular integrated development environment by Microsoft.
At 1:07, Tim creates a new Data folder and adds a courseData.json file. He mentions that his live site, timcorey.com, uses a similar system - just a big JSON file behind the scenes, acting as a web service.
Key points from Tim's setup:
This choice mirrors the REST (Representational State Transfer) principles of working with existing resources.
Tim carefully walks through the structure of the sample JSON file:
Tim explains at 3:29 that all pricing is based on US dollars; however, local taxes (VAT) might alter the final price.
Each of these fields later maps to a model class in C# - a foundational element in building ASP.NET Web APIs.
Moving into .NET Core coding, Tim creates a CourseModel.cs file inside a new Models folder.
At 4:47, he uses Visual Studio's "Paste Special > Paste JSON as Classes" to instantly scaffold a class based on the JSON structure. Tim points out:
Creating a strong model class is crucial for enabling data communication between clients and the server.
Tim continues by creating a CourseData.cs class to manage the loading of the course list into memory.
Key steps:
The courses are loaded into a public List<CourseModel> property, ensuring fast access without repeatedly hitting a database.
Tim at 11:04 stresses that if deserialization fails, a new empty list is created to prevent null reference errors - a best practice when building robust APIs.
Next, Tim shows how to register the CourseData class using AddTransient in the services container.
He explains that even though the data is read-only, using a transient service avoids accidental modification issues. This approach aligns with modern ASP.NET Core Web API development standards.
At 14:03, Tim begins building endpoints for the sample API:
This modular approach simplifies scaling your Web API project - an essential technique when managing large HTTP services or multiple endpoints.

Tim also sets the launch URL to Swagger UI, making testing easy.
When testing the new endpoint, Tim encounters a status code error related to the CourseLengthInHours field. He realizes that some courses have fractional hours (like 2.5), requiring a double instead of int.
Tim corrects the CourseModel, demonstrating the value of thorough error checking and respecting data types when consuming external web resources.
Tim extends the functionality:
He improves error handling by checking if a course exists. If it doesn't, Tim uses return NotFound() - returning an appropriate HTTP status code to the client.
This matches RESTful architectural style practices, where each HTTP method clearly communicates the operation result.
A simple GET method isn't enough - real web services need filtering capabilities.
Tim enhances LoadAllCourses to accept query parameters:
He explains how to safely handle optional parameters using String.IsNullOrWhiteSpace.
Filtering by courseType uses RemoveAll with String.Compare, ignoring case differences. Searching the course name and short description uses .Contains with a case-insensitive comparison.
Tim tests scenarios like:
This provides a fully interactive experience for users across web apps, mobile apps, or clients communicating over HTTP. For more detailed information please refer to full video.
By the end of the lesson, Tim has created:
Tim previews that next, he'll handle Cross-Origin Resource Sharing (CORS) - critical for allowing internet clients and different domains to access the API freely.
Tim closes with encouragement: programming sometimes involves hurdles, but it's rewarding.
Following Tim Corey's video, you can create a new Web API project in Visual Studio, load sample data, build endpoints, and implement powerful filtering - all based on RESTful principles and ASP.NET Core standards.
Whether you're testing web pages, building APIs for mobile devices, or working with existing resources, this setup ensures fast, reliable access to data via HTTP methods.
Keep practicing these patterns in .NET Core, and soon you'll be creating robust web services that communicate smoothly between clients, servers, and the internet!
Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!
Join our newsletter, you’ll get exclusive access on article updates. We value your privacy