parent
7dc442cc0b
commit
0df0eae226
@ -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 @@ |
|||||||
|
@AspNetCoreApi_HostAddress = http://localhost:5184 |
||||||
|
|
||||||
|
GET {{AspNetCoreApi_HostAddress}}/weatherforecast/ |
||||||
|
Accept: application/json |
||||||
|
|
||||||
|
### |
@ -0,0 +1,33 @@ |
|||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace AspNetCoreApi.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,36 @@ |
|||||||
|
|
||||||
|
namespace AspNetCoreApi |
||||||
|
{ |
||||||
|
public class Program |
||||||
|
{ |
||||||
|
public static void Main(string[] args) |
||||||
|
{ |
||||||
|
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,13 @@ |
|||||||
|
namespace AspNetCoreApi |
||||||
|
{ |
||||||
|
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,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