From ab459155f52656655fa17e481a61648075935f16 Mon Sep 17 00:00:00 2001 From: polyphemus Date: Wed, 14 Oct 2026 12:09:21 +0300 Subject: [PATCH] API --- works/Api/lab-01/PokemonAPI/PokemonAPI.sln | 16 ++++++ .../PokemonAPI/PokemonAPI/PokemonAPI.csproj | 13 +++++ .../PokemonAPI/PokemonAPI/PokemonAPI.http | 6 +++ .../lab-01/PokemonAPI/PokemonAPI/Program.cs | 50 ++++++++++++++++++ .../PokemonAPI/Properties/launchSettings.json | 23 ++++++++ .../PokemonAPI/appsettings.Development.json | 8 +++ .../PokemonAPI/PokemonAPI/appsettings.json | 9 ++++ works/Api/lab-01/lab-01 - PokeAPI.zip | Bin 0 -> 3255 bytes 8 files changed, 125 insertions(+) create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI.sln create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json create mode 100644 works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json create mode 100644 works/Api/lab-01/lab-01 - PokeAPI.zip diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI.sln b/works/Api/lab-01/PokemonAPI/PokemonAPI.sln new file mode 100644 index 0000000..fdfb217 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokemonAPI", "PokemonAPI\PokemonAPI.csproj", "{AB656F88-0D39-4163-8984-28C83362611C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AB656F88-0D39-4163-8984-28C83362611C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AB656F88-0D39-4163-8984-28C83362611C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj new file mode 100644 index 0000000..3939e20 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.csproj @@ -0,0 +1,13 @@ + + + + net10.0 + enable + enable + + + + + + + diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http new file mode 100644 index 0000000..b2717a7 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/PokemonAPI.http @@ -0,0 +1,6 @@ +@PokemonAPI_HostAddress = http://localhost:5076 + +GET {{PokemonAPI_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs b/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs new file mode 100644 index 0000000..356dfce --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/Program.cs @@ -0,0 +1,50 @@ +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddOpenApi(); + +var app = builder.Build(); + +var pokemons = new List +{ + new(1, "Pikachu", "Electric", 12), + new(2, "Charmander", "Fire", 8), + new(3, "Squirtle", "Water", 10) +}; + +app.MapGet("/pokemons/{id}", (int id) => +{ + var pokemon = pokemons.FirstOrDefault(p => p.Id == id); + + if (pokemon != null) + { + return Results.Ok(pokemon); + } + else + { + return Results.NotFound(); + } +}); + +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); +} +app.MapGet("/hello", () => "Привет, мир API!"); +app.MapGet("/pokemons", () => Results.Ok(pokemons)); + + +app.Run(); + +public record Pokemon( + int Id, + string Name, + string Type, + int Level +); + +public record PokemonInput( + string Name, + string Type, + int Level +); + diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json new file mode 100644 index 0000000..80e65fa --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5076", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7190;http://localhost:5076", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/works/Api/lab-01/PokemonAPI/PokemonAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/works/Api/lab-01/lab-01 - PokeAPI.zip b/works/Api/lab-01/lab-01 - PokeAPI.zip new file mode 100644 index 0000000000000000000000000000000000000000..02c6123100f61b87fbf2413dd895dc8809c65bee GIT binary patch literal 3255 zcmZve2{e>@AIHaB89Rl9?6Ncs7sD_&VKNx9Cd+Gygoa@(V~;SAghms^jj~f2$}O%e z30KGxu6^GIQCVUryz_M5^EUIo{h#xk^PKZM-{<_!=l}cue_u<}Uswe}?DR`O-`p9* zusG?@%3fFk*2@nc=yBeb-P}ys1g5mmYuX9zo0+k;^~b=BJ54d2rd{V?3+){in3V2L z3#CpBj1993ffjhg4Miw7t~H+6L6Ha+287DVaSqp3XdCuF+S6&kOD!dHeL9bV!vK8;Yk z`InX^GDE(f?Vd1#b#7=st4$Cs>4}RBb&7wpMXA=+At}@HLe(8LGC{u=s`}SYFJ4!C zmbej$b@IFzpM`Hl-^^^4rOc9Armn|euZ&hyFN~lma(kHUC>o@j*VAdp{-GBZMX<1S z`fP{uNo6}fDlh-|Y&v(&ZFa@ni#7e@`{)~cPo%+{Q3pkm$VCN0F){js2?Dujdk+F~ z{$OZV^S8#{cW5F(ypp?gBql73&|p7-rp5%VOW&kfk3W7oDtpFRPd0WKE>q3#d`sey zncX?}-s~lc)=6c;Y8RP1k3BCFYU3v-;^yz5D|vf8H#H%~^*2q$v@mV|qu{xEFQQ?A zg49OuBe|^Z%+OP21h!%YVOH+aJ@POe8GdLhx*;ikH7dZ-&s6xVl`?w;5zcl7{-BoM zTMOj7d5Y*hyZg0iaUiAurZ+D7? zxlh-Fs_ld_sLETpISp$v#QJ1FKu_2)MOW5vayo9*2s=_}%SobcVFr5Na*Y(?=Ifl> z4Q)wf@aJiEJ0!z1g=sH#!2soLll~Scop3V~W&BSl!x<@?F*oHAL|u?{%~2h_zEaf` z46@HTz{V+A#&0bAj=o@J&pV;VcsVQndtYcYrAb(v^rK3c*xkh1<60anfqj+wuwDUD z7}oMgC-t3U2GWMD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