Skip to content

Commit cdccd99

Browse files
committed
"Create Api project"
1 parent 473c047 commit cdccd99

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
.idea/

GenerateUrlShortener.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UrlShortener.Api", "UrlShortener.Api\UrlShortener.Api.csproj", "{C41A51F9-0688-4F6A-8BC8-82EBEE9A14D0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{C41A51F9-0688-4F6A-8BC8-82EBEE9A14D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{C41A51F9-0688-4F6A-8BC8-82EBEE9A14D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{C41A51F9-0688-4F6A-8BC8-82EBEE9A14D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{C41A51F9-0688-4F6A-8BC8-82EBEE9A14D0}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

UrlShortener.Api/Api.http

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@Api_HostAddress = http://localhost:5003
2+
3+
GET {{Api_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###

UrlShortener.Api/Program.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
5+
builder.Services.AddOpenApi();
6+
7+
var app = builder.Build();
8+
9+
// Configure the HTTP request pipeline.
10+
if (app.Environment.IsDevelopment())
11+
{
12+
app.MapOpenApi();
13+
}
14+
15+
app.UseHttpsRedirection();
16+
17+
var summaries = new[]
18+
{
19+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
20+
};
21+
22+
app.MapGet("/weatherforecast", () =>
23+
{
24+
var forecast = Enumerable.Range(1, 5).Select(index =>
25+
new WeatherForecast
26+
(
27+
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
28+
Random.Shared.Next(-20, 55),
29+
summaries[Random.Shared.Next(summaries.Length)]
30+
))
31+
.ToArray();
32+
return forecast;
33+
})
34+
.WithName("GetWeatherForecast");
35+
36+
app.Run();
37+
38+
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
39+
{
40+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": false,
8+
"applicationUrl": "http://localhost:5003",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": false,
17+
"applicationUrl": "https://localhost:7125;http://localhost:5003",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

UrlShortener.Api/appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

0 commit comments

Comments
 (0)