Добавлен проект с Web API Server.

This commit is contained in:
Artyom 2024-04-15 19:31:53 +03:00
parent 468365e10a
commit e320118245
8 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc;
using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute;
namespace ApiServer.Controllers
{
[ApiController]
[Route("api")]
public class PostContoller
{
[HttpGet]
[Route("post")]
public string GetUserPost()
{
return "Hello, user! Your post is best!";
}
[HttpGet]
[Route("adminpost")]
public string GetAdmin()
{
return "Hello, Admin! It's your POST!!!";
}
}
}

View File

@ -0,0 +1,23 @@
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.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:3819",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:12345",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

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

View File

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

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BerklySocketServer", "CyberSystem\BerklySocketServer.csproj", "{732F06D2-F9CE-40A3-8281-48D7A41E0F79}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BerklySocketServer", "CyberSystem\BerklySocketServer.csproj", "{732F06D2-F9CE-40A3-8281-48D7A41E0F79}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiServer", "ApiServer\ApiServer.csproj", "{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Debug|Any CPU.Build.0 = Debug|Any CPU {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.ActiveCfg = Release|Any CPU {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.Build.0 = Release|Any CPU {732F06D2-F9CE-40A3-8281-48D7A41E0F79}.Release|Any CPU.Build.0 = Release|Any CPU
{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C72B3F0-8B39-4D48-8D9B-9A56046E5DA8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -8,7 +8,7 @@ public class Server
public static void Main() public static void Main()
{ {
// Настройка IP-адреса сервера и номера порта. // Настройка IP-адреса сервера и номера порта.
var serverAddress = IPAddress.Parse("127.0.0.7"); var serverAddress = IPAddress.Parse("0.0.0.0");
var serverPort = 8000; var serverPort = 8000;
// Создаем наш серверный сокет. // Создаем наш серверный сокет.