parent
dad2570945
commit
0dd6a438d5
@ -0,0 +1,32 @@ |
||||
using Microsoft.AspNetCore.Mvc; |
||||
|
||||
namespace WebApi.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 = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), |
||||
TemperatureC = Random.Shared.Next(-20, 55), |
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] |
||||
}) |
||||
.ToArray(); |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
var builder = WebApplication.CreateBuilder(args); |
||||
|
||||
// Add services to the container. |
||||
|
||||
builder.Services.AddControllers(); |
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
||||
builder.Services.AddEndpointsApiExplorer(); |
||||
builder.Services.AddSwaggerGen(); |
||||
|
||||
var app = builder.Build(); |
||||
|
||||
// Configure the HTTP request pipeline. |
||||
if (app.Environment.IsDevelopment()) |
||||
{ |
||||
app.UseSwagger(); |
||||
app.UseSwaggerUI(); |
||||
} |
||||
|
||||
app.UseHttpsRedirection(); |
||||
|
||||
app.UseAuthorization(); |
||||
|
||||
app.MapControllers(); |
||||
|
||||
app.Run(); |
@ -0,0 +1,12 @@ |
||||
namespace WebApi; |
||||
|
||||
public class WeatherForecast |
||||
{ |
||||
public DateOnly Date { get; set; } |
||||
|
||||
public int TemperatureC { get; set; } |
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |
||||
|
||||
public string? Summary { get; set; } |
||||
} |
@ -0,0 +1,13 @@ |
||||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
||||
<PropertyGroup> |
||||
<TargetFramework>net8.0</TargetFramework> |
||||
<Nullable>enable</Nullable> |
||||
<ImplicitUsings>enable</ImplicitUsings> |
||||
</PropertyGroup> |
||||
|
||||
<ItemGroup> |
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> |
||||
</ItemGroup> |
||||
|
||||
</Project> |
@ -0,0 +1,6 @@ |
||||
@WebApi_HostAddress = http://localhost:5002 |
||||
|
||||
GET {{WebApi_HostAddress}}/weatherforecast/ |
||||
Accept: application/json |
||||
|
||||
### |
@ -0,0 +1,8 @@ |
||||
{ |
||||
"Logging": { |
||||
"LogLevel": { |
||||
"Default": "Information", |
||||
"Microsoft.AspNetCore": "Warning" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
{ |
||||
"Logging": { |
||||
"LogLevel": { |
||||
"Default": "Information", |
||||
"Microsoft.AspNetCore": "Warning" |
||||
} |
||||
}, |
||||
"AllowedHosts": "*" |
||||
} |
Loading…
Reference in new issue