parent
91f89c795b
commit
cc970b09f2
@ -0,0 +1,33 @@ |
||||
using Microsoft.AspNetCore.Mvc; |
||||
|
||||
namespace WebAPIWithEF.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 WebAPIWithEF |
||||
{ |
||||
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 WebAPIWithEF |
||||
{ |
||||
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,6 @@ |
||||
@WebAPIWithEF_HostAddress = http://localhost:5057 |
||||
|
||||
GET {{WebAPIWithEF_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