All Projects → giraffe-fsharp → Giraffe.Razor

giraffe-fsharp / Giraffe.Razor

Licence: Apache-2.0 license
Razor view engine http handlers for Giraffe web applications.

Programming Languages

F#
602 projects

Projects that are alternatives of or similar to Giraffe.Razor

Giraffe
Giraffe is an F# micro web framework for building rich web applications. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware. Giraffe applications are composed of so called HttpHandler functions which can be thought of a mixture of Suave's WebParts and ASP.NET Core's middleware.
Stars: ✭ 1,703 (+6207.41%)
Mutual labels:  template-engine, aspnet-core, http-handler, giraffe
Giraffe.TokenRouter
Alternative routing API for Giraffe web applications which is aimed at maximum performance.
Stars: ✭ 21 (-22.22%)
Mutual labels:  aspnet-core, http-handler, giraffe
BlazorDemo
Demo application for my writings about Blazor
Stars: ✭ 79 (+192.59%)
Mutual labels:  aspnet-core, razor
AspNetCoreAzureSearch
ASP.NET Core with Azure Cognitive Search
Stars: ✭ 12 (-55.56%)
Mutual labels:  aspnet-core, razor
Dasblog Core
The original DasBlog reimagined with ASP.NET Core
Stars: ✭ 252 (+833.33%)
Mutual labels:  aspnet-core, razor
essential-templating
A set of templating libraries.
Stars: ✭ 21 (-22.22%)
Mutual labels:  template-engine, razorengine
AspNetCoreMvcSharedLocalization
ASP.NET Core MVC shared localization
Stars: ✭ 31 (+14.81%)
Mutual labels:  aspnet-core, razor
FlexDotnetCMS
A powerful, flexible, decoupled and easy to use and Fully Featured ASP .NET CMS, it can also be used as a Headless CMS
Stars: ✭ 45 (+66.67%)
Mutual labels:  razor, razorengine
Westwind.razorhosting
Hosting the Razor Runtime outside of ASP.NET/MVC for use in non-Web .NET applications.
Stars: ✭ 136 (+403.7%)
Mutual labels:  template-engine, razor
Razorlight
Template engine based on Microsoft's Razor parsing engine for .NET Core
Stars: ✭ 1,068 (+3855.56%)
Mutual labels:  template-engine, razor
Diamond
Diamond is a full-stack web-framework written in The D Programming Language using vibe.d
Stars: ✭ 173 (+540.74%)
Mutual labels:  template-engine, razor
DNTCommon.Web.Core
DNTCommon.Web.Core provides common scenarios' solutions for ASP.NET Core 3.x applications.
Stars: ✭ 117 (+333.33%)
Mutual labels:  aspnet-core, razor
cinje
A Pythonic and ultra fast template engine DSL.
Stars: ✭ 26 (-3.7%)
Mutual labels:  template-engine
run-aspnetcore-blazor
New .Net Core 3.0 Asp.Net Blazor Components SPA Web Application
Stars: ✭ 22 (-18.52%)
Mutual labels:  aspnet-core
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+688.89%)
Mutual labels:  aspnet-core
cottle
High performance template engine for C#
Stars: ✭ 99 (+266.67%)
Mutual labels:  template-engine
nhplate
Net Heroes Template Engine for Node.js and browsers
Stars: ✭ 26 (-3.7%)
Mutual labels:  template-engine
emplea do
Open source tech jobs portal. Made with .Net Core
Stars: ✭ 75 (+177.78%)
Mutual labels:  aspnet-core
mole
A tool for managing design decision outputs for different platforms
Stars: ✭ 30 (+11.11%)
Mutual labels:  template-engine
handlers
Go's HTTP handlers I use in my projects
Stars: ✭ 53 (+96.3%)
Mutual labels:  http-handler

Giraffe

Giraffe.Razor

Razor view engine support for the Giraffe web framework.

NuGet Info

Linux, macOS and Windows Build Status

.NET Core

Build history

Table of contents

Documentation

The Giraffe.Razor NuGet package adds additional HttpHandler functions to render Razor views in Giraffe.

In order to use the Razor functionality in an (ASP.NET Core) Giraffe application you'll need to register additional dependencies through the AddRazorEngine extension method during application start-up:

open Giraffe
open Giraffe.Razor

type Startup() =
    member __.ConfigureServices (svc : IServiceCollection,
                                 env : IHostingEnvironment) =
        let viewsFolderPath =
            Path.Combine(env.ContentRootPath, "Views")
        svc.AddRazorEngine viewsFolderPath |> ignore

If your all of your Razor views are kept in a Razor class library, then you do not need to specify a views folder path when registering the Razor dependencies. In this case there is an overload of AddRazorEngine which takes no arguments:

open Giraffe
open Giraffe.Razor

type Startup() =
    member __.ConfigureServices (svc : IServiceCollection,
                                 env : IHostingEnvironment) =
        svc.AddRazorEngine() |> ignore

razorView

The razorView http handler utilises the official ASP.NET Core MVC Razor view engine to compile a view into a HTML page and sets the body of the HttpResponse object. It requires the content type, the view name, an optional view model, an optional view data dictionary, and an optional model state dictionary as input parameters.

Example:

Use the razorView function:

open Giraffe
open Giraffe.Razor

[<CLIMutable>]
type TestModel =
    {
        WelcomeText : string
    }

let model = { WelcomeText = "Hello, World" }

let app =
    choose [
        // Assuming there is a view called "Index.cshtml"
        route  "/" >=> razorView "text/html" "Index" (Some model) None None
    ]

razorHtmlView

The razorHtmlView http handler is the same as the razorView handler except that it automatically sets the response's content type to text/html; charset=utf-8.

Example:

Use the razorView function:

open Giraffe
open Giraffe.Razor
open Microsoft.AspNetCore.Mvc.ModelBinding

[<CLIMutable>]
type TestModel =
    {
        WelcomeText : string
    }

let model = { WelcomeText = "Hello, World" }

let viewData =
    dict [
        "Title", "Hello World" :> obj
        "Foo", 89 :> obj
        "Bar", true :> obj
    ]

let modelState = ModelStateDictionary()

let app =
    choose [
        // Assuming there is a view called "Index.cshtml"
        route  "/" >=> razorHtmlView "Index" (Some model) (Some viewData) (Some modelState)
    ]

validateAntiforgeryToken

The validateAntiforgeryToken http handler allows one to validate an anti forgery token created by the Microsoft.AspNetCore.Antiforgery API.

Example:

Inside a razor view add an anti forgery token:

<form action="/submit-sth">
   @Html.AntiforgeryToken
   <input type="submit">
</form>

Use the validateAntiforgeryToken function to validate the form request:

open Giraffe
open Giraffe.Razor

let invalidCSRFTokenHandler = RequestErrors.badRequest "The CSRF token was invalid"

let app =
    POST
    >=> route "/submit-sth"
    >=> validateAntiforgeryToken invalidCSRFTokenHandler
    >=> Successful.OK "All good"

Samples

Please find a fully functioning sample application under ./samples/GiraffeRazorSample/.

Nightly builds and NuGet feed

All official release packages are published to the official and public NuGet feed.

Nightly builds (builds from the develop branch) produce unofficial pre-release packages which can be pulled from the project's NuGet feed on GitHub.

These packages are being tagged with the Workflow's run number as the package version.

All other builds, such as builds triggered by pull requests produce a NuGet package which can be downloaded as an artifact from the individual GitHub action.

More information

For more information about Giraffe, how to set up a development environment, contribution guidelines and more please visit the main documentation page.

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].