Strongly typed HTML templates with FSharp without a framework

But, is there a solution?

  • Paket is dependency manager for .NET project, that among other nice features has the concept of a single file reference: you can declare a dependency just as a file, for example from a GitHub project.
  • Giraffe is an F# web framework, it’s default view engine is just a single file with no additional dependencies. And since views are just regular F# code, it just works: no additional tooling or build steps needed!

How to do it?

dotnet new console -lang F# -o src/GiraffeHtmlService
dotnet run — project .\src\GiraffeHtmlService\
> dotnet run --project .\src\GiraffeHtmlService\
The rendered html document:
<!DOCTYPE html>
<html><body><div>Hello World!</div></body></html>

So, a recap

  • Strongly typed
  • Syntax highlight and intellisense works
  • No additional build step, no project file hacking
  • No dependency on a whole web stack, just add a single file!

Gotchas?

And thank you!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akos Lukacs

Akos Lukacs

More from Medium

Evolution of my Dev Environment

Minimal APIs in .NET 6: how to use it to enrich data for analytics — Part2

Asp.net Bind GridView Using DataTable Linq to Sql

Pizza WebApp Using ASP.net (Razor Pages, SQL Database, Entity Framework)