Skip to content

Commit

Permalink
add webapi project
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Feb 12, 2024
1 parent 473b625 commit 09f5858
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Nager.PublicSuffix.WebApi/Nager.PublicSuffix.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Nager.PublicSuffix\Nager.PublicSuffix.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions src/Nager.PublicSuffix.WebApi/Nager.PublicSuffix.WebApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@Nager.PublicSuffix.WebApi_HostAddress = http://localhost:5096

GET {{Nager.PublicSuffix.WebApi_HostAddress}}/DomainInfo/test.de/
Accept: application/json
###

GET {{Nager.PublicSuffix.WebApi_HostAddress}}/DomainInfo/mail.test.de/
Accept: application/json

###
42 changes: 42 additions & 0 deletions src/Nager.PublicSuffix.WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Nager.PublicSuffix;
using Nager.PublicSuffix.RuleProviders;
using System.Text.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddHttpClient();
builder.Services.AddSingleton<IRuleProvider, WebRuleProvider>();
builder.Services.AddSingleton<IDomainParser, DomainParser>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(opt =>
{
opt.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
});

var app = builder.Build();

var ruleProvider = app.Services.GetService<IRuleProvider>();
await ruleProvider.BuildAsync();

Check warning on line 25 in src/Nager.PublicSuffix.WebApi/Program.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.MapGet("/DomainInfo/{domain}", (string domain, IDomainParser domainParser) =>
{
var domainInfo = domainParser.Parse(domain);
return domainInfo;
})
.WithName("DomainInfo")
.WithOpenApi();

app.Run();
15 changes: 15 additions & 0 deletions src/Nager.PublicSuffix.WebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5096"
}
},
"$schema": "http://json.schemastore.org/launchsettings.json"
}
8 changes: 8 additions & 0 deletions src/Nager.PublicSuffix.WebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/Nager.PublicSuffix.WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
6 changes: 6 additions & 0 deletions src/Nager.PublicSuffix.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nager.PublicSuffix", "Nager
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nager.PublicSuffix.UnitTest", "Nager.PublicSuffix.UnitTest\Nager.PublicSuffix.UnitTest.csproj", "{09196C00-837C-4980-AF04-3F7B3ED8049C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nager.PublicSuffix.WebApi", "Nager.PublicSuffix.WebApi\Nager.PublicSuffix.WebApi.csproj", "{C11F3A04-C675-493F-9F9A-5CC0EB5AB231}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{09196C00-837C-4980-AF04-3F7B3ED8049C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09196C00-837C-4980-AF04-3F7B3ED8049C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09196C00-837C-4980-AF04-3F7B3ED8049C}.Release|Any CPU.Build.0 = Release|Any CPU
{C11F3A04-C675-493F-9F9A-5CC0EB5AB231}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C11F3A04-C675-493F-9F9A-5CC0EB5AB231}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C11F3A04-C675-493F-9F9A-5CC0EB5AB231}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C11F3A04-C675-493F-9F9A-5CC0EB5AB231}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 09f5858

Please sign in to comment.