https://github.com/openfaas/dotnet-templates
Templates for .NET
https://github.com/openfaas/dotnet-templates
Last synced: 9 months ago
JSON representation
Templates for .NET
- Host: GitHub
- URL: https://github.com/openfaas/dotnet-templates
- Owner: openfaas
- License: mit
- Created: 2024-04-16T14:46:25.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T11:42:02.000Z (about 2 years ago)
- Last Synced: 2025-03-01T00:34:19.404Z (over 1 year ago)
- Language: C#
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dotnet-templates
Templates for .NET
## dotnet8-csharp
This template uses the ASP.net minimal API style, and exposes a static function to register HTTP handlers. It is multi-arch, and supports Linux for amd64 and Arm64 via `faas-cli publish` or `faas-cli up --publish`.
Register a `/hello` as an endpoint:
```csharp
public static void MapEndpoints(WebApplication app) {
app.MapGet("/hello", () => "Hello, world!");
}
```
The `RegisterServices` method can be used to configure any WebApplication services such as Swagger generators.
```csharp
public static void MapServices(IServiceCollection services)
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
}
```
Pull the template:
```bash
faas-cli template pull https://github.com/openfaas/dotnet-templates
```
Create a new function using the template:
```bash
export PREFIX="ttl.sh"
faas-cli new --lang dotnet8-csharp $PREFIX hello-world
```
## Adding static files
If a folder named static is found in the root of your function's source code, **it will be copied** into the final image published for your function.
To serve the contents of the static folder you can setup the file server in `Handler.cs`.
```c#
public static void MapEndpoints(WebApplication app) {
app.UseStaticFiles();
}
```