Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added first #329

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions v2/rscg_examples/Immediate.Apis/description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"generator":{
"name":"Immediate.Apis",
"nuget":[
"https://www.nuget.org/packages/Immediate.Apis/"
],
"link":"https://github.com/immediateplatform/immediate.apis",
"author":"Stuart Turner",
"source":"https://github.com/immediateplatform/immediate.apis"
},
"data":{
"goodFor":["Registering APIs similar to controllers in ASP.NET Core"],
"csprojDemo":"Immediate.ApisDemo.csproj",
"csFiles":["Program.cs"],
"excludeDirectoryGenerated":[""],
"includeAdditionalFiles":[""]
},
"links":{
"blog":"",
"video":""
}
}
25 changes: 25 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APIDemo", "APIDemo\APIDemo.csproj", "{58E33B78-4B6E-467B-B2A3-C83005FDE6C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58E33B78-4B6E-467B-B2A3-C83005FDE6C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58E33B78-4B6E-467B-B2A3-C83005FDE6C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58E33B78-4B6E-467B-B2A3-C83005FDE6C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58E33B78-4B6E-467B-B2A3-C83005FDE6C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9E1B2E7-FF28-4E01-9514-17BD0BF4675E}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo/APIDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Immediate.Apis" Version="1.3.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo/APIDemo.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@APIDemo_HostAddress = http://localhost:5233

GET {{APIDemo_HostAddress}}/weatherforecast/
Accept: application/json

###
7 changes: 7 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace APIDemo;

public class Person
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
}
21 changes: 21 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo/PersonAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Http.HttpResults;
namespace APIDemo;

[Handler]
[MapGet("/users")]
public static partial class PersonAPI
{
public record Query;

private static async ValueTask<Person[]> HandleAsync(
Query _,
CancellationToken token)
{
await Task.Delay(1000);
return new[] { new Person { FirstName = "Ignat", LastName = "Andrei" } };
}
}


46 changes: 46 additions & 0 deletions v2/rscg_examples/Immediate.Apis/src/APIDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using APIDemo;
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddAPIDemoHandlers();
var app = builder.Build();

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

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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:11969",
"sslPort": 44318
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5233",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5233",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
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 v2/rscg_examples/Immediate.Apis/src/APIDemo/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading