create RestApi project
This commit is contained in:
parent
6156072436
commit
b8b48cbf7e
25
ComputerShop.sln
Normal file
25
ComputerShop.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.8.34511.84
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopRestApi", "ComputerShopRestApi\ComputerShopRestApi.csproj", "{2C36A31D-FD74-4E83-A271-1F300D008E26}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2C36A31D-FD74-4E83-A271-1F300D008E26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{2C36A31D-FD74-4E83-A271-1F300D008E26}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{2C36A31D-FD74-4E83-A271-1F300D008E26}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{2C36A31D-FD74-4E83-A271-1F300D008E26}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {9414A502-1CCD-466A-9FFA-21B0297A8ECA}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
13
ComputerShopRestApi/ComputerShopRestApi.csproj
Normal file
13
ComputerShopRestApi/ComputerShopRestApi.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
33
ComputerShopRestApi/Controllers/WeatherForecastController.cs
Normal file
33
ComputerShopRestApi/Controllers/WeatherForecastController.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ComputerShopRestApi.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class WeatherForecastController : ControllerBase
|
||||||
|
{
|
||||||
|
private static readonly string[] Summaries = new[]
|
||||||
|
{
|
||||||
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly ILogger<WeatherForecastController> _logger;
|
||||||
|
|
||||||
|
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(Name = "GetWeatherForecast")]
|
||||||
|
public IEnumerable<WeatherForecast> Get()
|
||||||
|
{
|
||||||
|
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||||
|
{
|
||||||
|
Date = DateTime.Now.AddDays(index),
|
||||||
|
TemperatureC = Random.Shared.Next(-20, 55),
|
||||||
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
ComputerShopRestApi/Program.cs
Normal file
19
ComputerShopRestApi/Program.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
var Builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
Builder.Services.AddControllers();
|
||||||
|
Builder.Services.AddEndpointsApiExplorer();
|
||||||
|
Builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var App = Builder.Build();
|
||||||
|
|
||||||
|
if (App.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
App.UseSwagger();
|
||||||
|
App.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
App.UseHttpsRedirection();
|
||||||
|
App.UseAuthorization();
|
||||||
|
App.MapControllers();
|
||||||
|
|
||||||
|
App.Run();
|
31
ComputerShopRestApi/Properties/launchSettings.json
Normal file
31
ComputerShopRestApi/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:32604",
|
||||||
|
"sslPort": 44351
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"ComputerShopRestApi": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7223;http://localhost:5055",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
ComputerShopRestApi/WeatherForecast.cs
Normal file
13
ComputerShopRestApi/WeatherForecast.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace ComputerShopRestApi
|
||||||
|
{
|
||||||
|
public class WeatherForecast
|
||||||
|
{
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
public int TemperatureC { get; set; }
|
||||||
|
|
||||||
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||||
|
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
}
|
||||||
|
}
|
8
ComputerShopRestApi/appsettings.Development.json
Normal file
8
ComputerShopRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
ComputerShopRestApi/appsettings.json
Normal file
9
ComputerShopRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user