Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Overview of .Net Core Web API Project Structure - Step by Step Guide

Find below structure of Solution Explorer: 




How to Create Project : YouTube Video Link: https://youtu.be/MKY1f93wC8Y


Explanation for each Files and Folders:

 

Connected Services:

 Connected Services is a feature in Visual Studio that allows you to connect your .NET Core project to external services with minimal code and configuration.

 

Main Uses:

Use Case

Description

Add REST APIs

Automatically generate C# client classes from an external API specification

Add Azure services

Easily hook your app into Azure Storage, Azure AD, Cosmos DB, etc.

Add WCF Web Services

Generate proxy classes to consume older WCF SOAP services.

Service Reference

Add service references from .wsdl or. json definitions

 

Example: Adding a REST API via OpenAPI

1. Right-click on your project → Add → Connected Service   -> If Connected Service option not available.

2. Choose OpenAPI (REST)

3. Provide the Swagger/OpenAPI URL (e.g.,https://api.example.com/swagger/v1/swagger.json)

4. Visual Studio generates the HttpClient wrapper for you.

5.  Use it like this:

    var client = new MyApiClient(httpClient);

    var result = await client.GetWeatherAsync();

1.   

Advantages:

1.      You don't need to write HttpClient calls manually.

2.      Simplifies integration with cloud or third-party services.

3.      Auto-updates client code when the service definition changes.


Dependencies:

In a .NET Core project, the Dependencies node in Solution Explorer shows all the external NuGet packages, frameworks, and project references your app needs to build and run.

 

Purpose:

-          🔁 Manage NuGet packages (e.g., Newtonsoft.Json, EntityFrameworkCore).

-          🧱 Reference other projects/libraries in your solution.

-          ⚙️ Target framework info (like .NET 6, .NET 8).

 

Properties:

launchSettings.json is a configuration file found under the Properties/ folder in a .NET Core project.

 

Purpose:

It defines how the app should start during development, including:

-          🌐 Profiles for running via IIS Express, Kestrel, or other environments.

-          🔢 Application URLs (e.g., http://localhost:5000).

-          📛 Environment variables (like ASPNETCORE_ENVIRONMENT).

 

A screenshot of a computer

AI-generated content may be incorrect.

In short – This file controls how your app runs locally during development, including ports, environment and browser launching.

Controllers:

A Controller in .NET Core is a C# class that handles incoming HTTP requests and returns responses—usually in APIs or MVC apps.

 

Purpose:

-          🧭 Acts as a bridge between the client and business logic.

-          📥 Handles GET, POST, PUT, DELETE requests.

-          📤 Returns data (JSON, views, etc.) to the client

               

Example:

A screenshot of a computer

AI-generated content may be incorrect.

             

Appsetting.json:

appsettings.json is a configuration file used to store application settings like connection strings, logging levels, and custom config values.

 

Purpose:

-          📦 Central place for storing config.

-          🌍 Supports environment-based settings (e.g., appsettings.Development.json).

-          🧪 Easily read via dependency injection using IConfiguration.

 

A close-up of a blue box

AI-generated content may be incorrect.

 

By default, an appsettings.Development.json file is provided. You can create additional environment-specific configuration files such as appsettings.QA.json, appsettings.UAT.json, or appsettings.Production.json to maintain separate settings for each environment.

 

A screenshot of a computer screen

AI-generated content may be incorrect.

 

A screenshot of a computer

AI-generated content may be incorrect.

 

 

1. appsettings.json is the base configuration file and is always loaded first.

2. appsettings.Development.json is loaded next, depending on the current environment.

3. The environment is defined using the ASPNETCORE_ENVIRONMENT variable (set in launchSettings.json).

 

Core_WebAPI.http:

It is REST client file (used in Visual Studio or VS Code) that lets you send HTTP requests (GET, POST, etc.) directly from your IDE to test your Web API endpoints.

 

Purpose:

-          🚀 Quickly test your API endpoints without Postman.

-          ✍️ Write and run requests inline in the .http file.

-          📄 Save common test requests as part of your project.

 

Example:

A screen shot of a computer

AI-generated content may be incorrect.

 

WeatherForecast.cs:

WeatherForecast.cs is a sample model class auto-generated when you create a new Web API project using the .NET Core template.

 

Purpose:

-          🧪 Acts as a demo data model for the sample WeatherForecastController.

-          📄 Defines properties like Date, TemperatureC, Summary used in the API.

 

Example:

A screenshot of a computer

AI-generated content may be incorrect.




Post a Comment

0 Comments