This commit is contained in:
Fernando Araoz 2025-01-24 06:27:32 -05:00
commit b6d174bf1b
8 changed files with 176 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
[Bb]in/
[Oo]bj/
.vs/
.idea/
*.user
*.userosscache
*.sln.docstates
*.suo
*.DS_Store
Thumbs.db
.idea/
*.sln.iml
.idea/**/workspace.xml
appsettings.*.json
!appsettings.json
!appsettings.Example.json
*.dbmdl
*.jfm
*.pfx
*.publishsettings
*.nupkg
**/packages/*
!**/packages/build/
*.nuget.props
*.nuget.targets
# build artifacts
out

View File

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
namespace MyApp.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();
}
}

30
DOCUMENTATION.md Normal file
View File

@ -0,0 +1,30 @@
# Documentacion
ASP.NET core controllers API 9.0
https://dotnet.microsoft.com/en-us/apps/aspnet
## Tipos de APIs en aspnet
- Minimal - Parecido a express
- Controllers - Parecido a Nestjs, estructurado, completo
- [aspnet core 9 api](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/apis?view=aspnetcore-9.0)
- [aspnet controllers](https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-9.0)
- [tutorial para crear proyecto nuevo](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-9.0)
## Creación del proyecto
> Reemplazar `MyApp` con el nombre del proyecto, por ejemplo `Trazo`.
Con Docker, ejecutar el comando:
```sh
docker run --rm -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:9.0 sh -c "cd /app && dotnet new webapi --use-controllers -o MyApp && chown -R $(id -u):$(id -g) MyApp"
```
para crear un proyecto nuevo, vacio, sin tener que instalar ningun programa.

13
MyApp.csproj Normal file
View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
</ItemGroup>
</Project>

23
Program.cs Normal file
View File

@ -0,0 +1,23 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5280",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7042;http://localhost:5280",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

12
WeatherForecast.cs Normal file
View File

@ -0,0 +1,12 @@
namespace MyApp;
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; }
}

9
appsettings.json Normal file
View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}