Skip to content

Commit

Permalink
Remove deprecated templates, add new controller-service
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Jun 28, 2024
1 parent 72ef2bf commit 0166da9
Show file tree
Hide file tree
Showing 78 changed files with 283 additions and 1,795 deletions.
2 changes: 1 addition & 1 deletion GenHTTP.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>

<PackageType>Template</PackageType>
<PackageVersion>8.3</PackageVersion>
<PackageVersion>8.5</PackageVersion>
<PackageId>GenHTTP.Templates</PackageId>

<Title>GenHTTP Templates</Title>
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ To use one of the templates below, create a new folder and run `dotnet new <temp

| Template | Description |
| ------------- |------------- |
| `genhttp-webservice` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/webservices). |
| `genhttp-webservice-minimal` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/functional) in a single file. |
| `genhttp-website` \[[deprecated](https://github.com/Kaliumhexacyanoferrat/GenHTTP/issues/496)\] | A [website](https://genhttp.org/documentation/content/websites), mainly for static content such as a business website. |
| `genhttp-website-mvc-razor` \[[deprecated](https://github.com/Kaliumhexacyanoferrat/GenHTTP/issues/496)\] | Dynamic website using the [MVC pattern](https://genhttp.org/documentation/content/controllers) and [Razor](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-5.0) as a templating engine. |
| `genhttp-website-mvc-scriban` \[[deprecated](https://github.com/Kaliumhexacyanoferrat/GenHTTP/issues/496)\] | Dynamic website using the [MVC pattern](https://genhttp.org/documentation/content/controllers) and [Scriban](https://github.com/scriban/scriban/) as a templating engine. |
| `genhttp-website-static` | Project to serve a [static website](https://genhttp.org/documentation/content/static-websites) from the file system. |
| `genhttp-spa` | Project to serve the distribution files of a [Single Page Application](https://genhttp.org/documentation/content/single-page-applications). |
| `genhttp-webservice` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/webservices). |
| `genhttp-webservice-minimal` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/functional) in a single file. |
| `genhttp-webservice-controllers` | A project that will host a new REST web service using [controllers](https://genhttp.org/documentation/content/frameworks/controllers). |
| `genhttp-website-static` | Project to serve a [static website](https://genhttp.org/documentation/content/frameworks/static-websites) from the file system. |
| `genhttp-spa` | Project to serve the distribution files of a [Single Page Application](https://genhttp.org/documentation/content/frameworks/single-page-applications). |

## Template Development

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

<ItemGroup>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />

<PackageReference Include="GenHTTP.Testing" Version="8.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="8.5.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="8.3.1" />
<PackageReference Include="GenHTTP.Core" Version="8.5.2" />

<PackageReference Include="GenHTTP.Modules.SinglePageApplications" Version="8.3.0" />
<PackageReference Include="GenHTTP.Modules.SinglePageApplications" Version="8.5.0" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

<ItemGroup>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />

<PackageReference Include="GenHTTP.Testing" Version="8.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="8.5.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

using GenHTTP.Testing;

namespace $safeprojectname$.Tests
namespace $safeprojectname$.Tests.Controllers
{

[TestClass]
public class WebsiteTests
public class DeviceControllerTests
{

[TestMethod]
public async Task TestGetAboutPage()
public async Task TestGetDevices()
{
using var runner = TestHost.Run(Project.Create());
using var runner = TestHost.Run(Project.Setup());

using var response = await runner.GetResponseAsync("/about");
using var response = await runner.GetResponseAsync("/devices/");

Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>

<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>

<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<AssemblyVersion>0.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
<Version>0.1.0</Version>

</PropertyGroup>

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="8.5.2" />

<PackageReference Include="GenHTTP.Modules.Security" Version="8.5.0" />
<PackageReference Include="GenHTTP.Modules.Controllers" Version="8.5.0" />

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;

using GenHTTP.Api.Protocol;

using GenHTTP.Modules.Controllers;

using $safeprojectname$.Model;

namespace $safeprojectname$.Controllers
{

// For documentation, see: https://genhttp.org/documentation/content/frameworks/controllers/

public class DeviceController
{

public List<DeviceSummary> Index()
{
// GET http://localhost:8080/devices/
return [new(Guid.NewGuid(), "Some Device")];
}

public DeviceDetails? Index([FromPath] Guid id)
{
// GET http://localhost:8080/devices/:id/
return new(id, "Some Device", "127.0.0.1");
}

[ControllerAction(RequestMethod.PUT)]
public Guid Add(DeviceDetails device)
{
// PUT http://localhost:8080/devices/add/
throw new NotImplementedException();
}

[ControllerAction(RequestMethod.POST)]
public Guid? Update(DeviceDetails book)
{
// POST http://localhost:8080/devices/update/
throw new NotImplementedException();
}

[ControllerAction(RequestMethod.DELETE)]
public Guid? Remove([FromPath] Guid id)
{
// DELETE http://localhost:8080/devices/remove/:id/
throw new NotImplementedException();
}

}

}
10 changes: 10 additions & 0 deletions Templates/Webservice-Controllers/$safeprojectname$/Model/Device.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace $safeprojectname$.Model
{

public record DeviceSummary(Guid ID, string Name);

public record DeviceDetails(Guid ID, string Name, string Address);

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using GenHTTP.Engine;

using GenHTTP.Modules.Practices;

using $safeprojectname$;

var project = Project.Create();

return Host.Create()
.Handler(project)
.Defaults()
.Console()
//-:cnd:noEmit
#if DEBUG
.Development()
#endif
//+:cnd:noEmit
using GenHTTP.Engine;

using GenHTTP.Modules.Practices;

using $safeprojectname$;

var project = Project.Setup();

return Host.Create()
.Handler(project)
.Defaults()
.Console()
//-:cnd:noEmit
#if DEBUG
.Development()
#endif
//+:cnd:noEmit
.Run();
24 changes: 24 additions & 0 deletions Templates/Webservice-Controllers/$safeprojectname$/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using GenHTTP.Api.Content;

using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Security;
using GenHTTP.Modules.Controllers;

using $safeprojectname$.Controllers;

namespace $safeprojectname$
{

public static class Project
{

public static IHandlerBuilder Setup()
{
return Layout.Create()
.AddController<DeviceController>("devices")
.Add(CorsPolicy.Permissive());
}

}

}
22 changes: 22 additions & 0 deletions Templates/Webservice-Controllers/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Andreas Nägeli",
"classifications": [ "GenHTTP", "Webservices", "REST", "Web API", "Controllers" ],
"identity": "GenHTTP.Templates.Webservice.Controllers",
"name": "GenHTTP: Webservice (Controllers)",
"shortName": "genhttp-webservice-controllers",
"sourceName": "$safeprojectname$",
"description": "A project template to host a REST webservice by utilizing controllers using the GenHTTP webserver",
"tags": {
"language": "C#",
"type": "project"
},
"primaryOutputs": [
{
"path": "$safeprojectname$\\$safeprojectname$.csproj"
},
{
"path": "$safeprojectname$.Tests\\$safeprojectname$.Tests.csproj"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-arm
# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-arm --no-restore /p:PublishTrimmed=true /p:TrimMode=Link
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm32v7
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./$safeprojectname$"]
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-arm

# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-arm --no-restore /p:PublishTrimmed=true /p:TrimMode=Link

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm32v7
WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./$safeprojectname$"]

EXPOSE 8080
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-arm64
# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-arm64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm64v8
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./$safeprojectname$"]
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-arm64

# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-arm64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-arm64v8
WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./$safeprojectname$"]

EXPOSE 8080
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-musl-x64
# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./$safeprojectname$"]
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY $safeprojectname$/*.csproj .
RUN dotnet restore -r linux-musl-x64

# copy and publish app and libraries
COPY $safeprojectname$/ .
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore /p:PublishTrimmed=true /p:TrimMode=Link

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine
WORKDIR /app
COPY --from=build /app .

ENTRYPOINT ["./$safeprojectname$"]

EXPOSE 8080
Loading

0 comments on commit 0166da9

Please sign in to comment.