From 77a34a878d74c26e2844f4813342ae1b1e3341df Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Tue, 1 Oct 2024 18:50:41 +0200 Subject: [PATCH] [+] First commit. --- .gitignore | 5 ++++ HubHarmony_api_template.sln | 16 ++++++++++ Program.cs | 53 ++++++++++++++++++++++++++++++++++ Properties/launchSettings.json | 41 ++++++++++++++++++++++++++ Simple API.csproj | 15 ++++++++++ Simple API.http | 6 ++++ appsettings.Development.json | 8 +++++ appsettings.json | 9 ++++++ 8 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 HubHarmony_api_template.sln create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 Simple API.csproj create mode 100644 Simple API.http create mode 100644 appsettings.Development.json create mode 100644 appsettings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/HubHarmony_api_template.sln b/HubHarmony_api_template.sln new file mode 100644 index 0000000..096bf98 --- /dev/null +++ b/HubHarmony_api_template.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple API", "Simple API.csproj", "{05654A4F-A7CA-4936-8A06-B62D48A716B2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {05654A4F-A7CA-4936-8A06-B62D48A716B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05654A4F-A7CA-4936-8A06-B62D48A716B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05654A4F-A7CA-4936-8A06-B62D48A716B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05654A4F-A7CA-4936-8A06-B62D48A716B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..3a1cbc1 --- /dev/null +++ b/Program.cs @@ -0,0 +1,53 @@ +var builder = WebApplication.CreateBuilder(args); + + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowAllOrigins", corsBuilder => + { + corsBuilder.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader(); + }); +}); + +var app = builder.Build(); + + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); +app.UseCors("AllowAllOrigins"); + +var summaries = new[] +{ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" +}; + +app.MapGet("/weatherforecast", () => + { + var forecast = Enumerable.Range(1, 5).Select(index => + new WeatherForecast + ( + DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + Random.Shared.Next(-20, 55), + summaries[Random.Shared.Next(summaries.Length)] + )) + .ToArray(); + return forecast; + }) + .WithName("GetWeatherForecast") + .WithOpenApi(); + +app.Run(); + +internal record WeatherForecast (DateOnly Date, int TemperatureC, string? Summary) +{ + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); +} \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..8528d37 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:37567", + "sslPort": 44390 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5094", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7076;http://localhost:5094", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Simple API.csproj b/Simple API.csproj new file mode 100644 index 0000000..79b6e71 --- /dev/null +++ b/Simple API.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + Simple_API + + + + + + + + diff --git a/Simple API.http b/Simple API.http new file mode 100644 index 0000000..4907fd5 --- /dev/null +++ b/Simple API.http @@ -0,0 +1,6 @@ +@Simple_API_HostAddress = http://localhost:5094 + +GET {{Simple_API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}