-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template which uses the functional framework (#5)
- Loading branch information
1 parent
0dd9b02
commit 0a1cae2
Showing
8 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Templates/Webservice-Minimal/$safeprojectname$/$safeprojectname$.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
|
||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<LangVersion>10.0</LangVersion> | ||
<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.0.0" /> | ||
|
||
<PackageReference Include="GenHTTP.Modules.Security" Version="8.0.0" /> | ||
<PackageReference Include="GenHTTP.Modules.Functional" Version="8.0.0" /> | ||
|
||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
|
||
using GenHTTP.Engine; | ||
|
||
using GenHTTP.Modules.Functional; | ||
using GenHTTP.Modules.Layouting; | ||
using GenHTTP.Modules.Practices; | ||
using GenHTTP.Modules.Security; | ||
|
||
// run this project and fetch a list of book records via http://localhost:8080/books/ | ||
var books = new List<Book>() | ||
{ | ||
new Book(1, "Lord of the Rings") | ||
}; | ||
|
||
// see https://genhttp.org/documentation/content/functional | ||
var bookApi = Inline.Create() | ||
.Get(() => books) | ||
.Put((Book book) => books.Add(book)); | ||
|
||
var content = Layout.Create() | ||
.Add("books", bookApi) | ||
.Add(CorsPolicy.Permissive()); | ||
|
||
return Host.Create() | ||
.Handler(content) | ||
.Defaults() | ||
.Console() | ||
//-:cnd:noEmit | ||
#if DEBUG | ||
.Development() | ||
#endif | ||
//+:cnd:noEmit | ||
.Run(); | ||
|
||
record class Book(int ID, string Title); |
14 changes: 14 additions & 0 deletions
14
Templates/Webservice-Minimal/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Andreas Nägeli", | ||
"classifications": [ "GenHTTP", "Webservices", "REST", "Web API" ], | ||
"identity": "GenHTTP.Templates.Webservice.Minimal", | ||
"name": "GenHTTP: Webservice (Minimal)", | ||
"shortName": "genhttp-webservice-minimal", | ||
"sourceName": "$safeprojectname$", | ||
"description": "A project template to host a REST webservice from a single code file using the GenHTTP webserver", | ||
"tags": { | ||
"language": "C#", | ||
"type": "project" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# $safeprojectname$ | ||
|
||
*Add your project description here.* | ||
|
||
## Development | ||
|
||
To build this project from source, checkout this repository and execute | ||
the following commands in your terminal. This requires the | ||
[.NET SDK](https://dotnet.microsoft.com/download) to be installed. | ||
|
||
``` | ||
cd $safeprojectname$ | ||
dotnet run | ||
``` | ||
|
||
This will make the service available at http://localhost:8080/. | ||
|
||
## Deployment | ||
|
||
To run this project with [Docker](https://www.docker.com/), run the | ||
following commands in your terminal (and adjust the first line | ||
depending on your platform). | ||
|
||
``` | ||
docker build -f Dockerfile.linux-x64 -t $safeprojectname$ . | ||
docker run -p 8080:8080 $safeprojectname$ | ||
``` | ||
|
||
## About | ||
|
||
This project uses the [GenHTTP webserver](https://genhttp.org/) to | ||
implement it's functionality. |