Skip to content

Commit 291aab2

Browse files
Add websocket template
1 parent 17f20f8 commit 291aab2

File tree

17 files changed

+306
-11
lines changed

17 files changed

+306
-11
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ dotnet new install GenHTTP.Templates
1717

1818
To use one of the templates below, create a new folder and run `dotnet new <template>` in your terminal.
1919

20-
| Template | Description |
21-
| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------|
22-
| `genhttp-webservice` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/webservices/). |
23-
| `genhttp-webservice-minimal` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/functional/) in a single file. |
20+
| Template | Description |
21+
|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
22+
| `genhttp-webservice` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/webservices/). |
23+
| `genhttp-webservice-minimal` | A project that will host a new [REST web service](https://genhttp.org/documentation/content/frameworks/functional/) in a single file. |
2424
| `genhttp-webservice-controllers` | A project that will host a new REST web service using [controllers](https://genhttp.org/documentation/content/frameworks/controllers/). |
25-
| `genhttp-website-static` | Project to serve a [static website](https://genhttp.org/documentation/content/frameworks/static-websites/) from the file system. |
26-
| `genhttp-spa` | Project to serve the distribution files of a [Single Page Application](https://genhttp.org/documentation/content/frameworks/single-page-applications/). |
25+
| `genhttp-websocket` | A project providing a web socket endpoint using the [websocket](https://genhttp.org/documentation/content/frameworks/websockets/) framework. |
26+
| `genhttp-website-static` | Project to serve a [static website](https://genhttp.org/documentation/content/frameworks/static-websites/) from the file system. |
27+
| `genhttp-spa` | Project to serve the distribution files of a [Single Page Application](https://genhttp.org/documentation/content/frameworks/single-page-applications/). |
2728

2829
## Template Development
2930

Templates/SinglePageApplication/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ docker run -p 8080:8080 $safeprojectname$
3030
## About
3131

3232
This project uses the [GenHTTP webserver](https://genhttp.org/) to
33-
implement it's functionality.
33+
implement its functionality.

Templates/Webservice-Controllers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ docker run -p 8080:8080 $safeprojectname$
3030
## About
3131

3232
This project uses the [GenHTTP webserver](https://genhttp.org/) to
33-
implement it's functionality.
33+
implement its functionality.

Templates/Webservice-Minimal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ docker run -p 8080:8080 $safeprojectname$
3030
## About
3131

3232
This project uses the [GenHTTP webserver](https://genhttp.org/) to
33-
implement it's functionality.
33+
implement its functionality.

Templates/Webservice/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ docker run -p 8080:8080 $safeprojectname$
3030
## About
3131

3232
This project uses the [GenHTTP webserver](https://genhttp.org/) to
33-
implement it's functionality.
33+
implement its functionality.

Templates/Website-Static/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ docker run -p 8080:8080 $safeprojectname$
3030
## About
3131

3232
This project uses the [GenHTTP webserver](https://genhttp.org/) to
33-
implement it's functionality.
33+
implement its functionality.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
5+
<TargetFramework>net9.0</TargetFramework>
6+
7+
<Nullable>enable</Nullable>
8+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
9+
<ImplicitUsings>true</ImplicitUsings>
10+
11+
<IsPackable>false</IsPackable>
12+
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
18+
19+
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
20+
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
21+
22+
<PackageReference Include="GenHTTP.Testing" Version="9.0.0" />
23+
24+
<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />
25+
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Net;
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
using GenHTTP.Testing;
6+
7+
namespace $safeprojectname$.Tests;
8+
9+
[TestClass]
10+
public class SocketTests
11+
{
12+
13+
[TestMethod]
14+
public async Task TestSocket()
15+
{
16+
using var runner = TestHost.Run(Project.Setup());
17+
18+
// add your test code here, e.g. using Websocket.Client
19+
}
20+
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
5+
<OutputType>Exe</OutputType>
6+
<TargetFramework>net9.0</TargetFramework>
7+
8+
<Nullable>enable</Nullable>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
10+
<ImplicitUsings>true</ImplicitUsings>
11+
12+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
13+
<FileVersion>0.1.0.0</FileVersion>
14+
<Version>0.1.0</Version>
15+
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
20+
<PackageReference Include="GenHTTP.Core" Version="9.0.0" />
21+
22+
<PackageReference Include="GenHTTP.Modules.Websockets" Version="9.0.0" />
23+
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
28+
<EmbeddedResource Include="Resources\client.html" />
29+
30+
</ItemGroup>
31+
32+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using GenHTTP.Engine;
2+
3+
using GenHTTP.Modules.Practices;
4+
5+
using $safeprojectname$;
6+
7+
// run this sample and open http://localhost:8080 in your browser
8+
9+
var project = Project.Setup();
10+
11+
return Host.Create()
12+
.Handler(project)
13+
.Defaults()
14+
.Console()
15+
//-:cnd:noEmit
16+
#if DEBUG
17+
.Development()
18+
#endif
19+
//+:cnd:noEmit
20+
.Run();

0 commit comments

Comments
 (0)