ASP.NET Core middleware to run Suave on top of ASP.NET Core
C# F# HTML
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Suave.AspNetCore Updated to Suave 2.0.3 Feb 17, 2017
test
.gitignore Initial commit Sep 1, 2016
LICENSE Initial commit Sep 1, 2016
README.md
Suave.AspNetCore.sln
appveyor.yml added appveyor build Dec 13, 2016
global.json Removed redundant websocket stuff Jan 19, 2017
suave.png

README.md

Suave.AspNetCore

Suave.AspNetCore is a small .NET Core library which provides an ASP.NET Core middleware to run a Suave app (on top of Kestrel) within ASP.NET Core.

Build status NuGet Info

Build history

Current release information

The current version has a dependency on Suave 2.0.2, and supports Suave's web request handling and the ErrorHandler function.

If you wish to use web sockets in ASP.NET Core please check out the ASP.NET Core Web Sockets project.

Framework support

Framework Supported versions
.NET Standard >= 1.6
Full .NET >= 4.6

Setup

Install NuGet package

PM> Install-Package Suave.AspNetCore

Create a Suave web app

open Suave
open Suave.Operators
open Suave.Successful

module App =
    let helloWorld =
        fun (ctx : HttpContext) ->
            OK "Hello World from Suave" ctx

Add Suave middleware to ASP.NET Core

type Startup() =
    member __.Configure (app : IApplicationBuilder)
                        (env : IHostingEnvironment)
                        (loggerFactory : ILoggerFactory) =
        app.UseSuave(App.helloWorld) |> ignore

Optionally you can also register a Suave ErrorHandler function to deal with unhandleded exceptions:

type Startup() =
    member __.Configure (app : IApplicationBuilder)
                        (env : IHostingEnvironment)
                        (loggerFactory : ILoggerFactory) =

        // Make sure to register the error handler as the very first middleware
        app.UseSuaveErrorHandler(App.errorHandler) |> ignore

        app.UseSuave(App.helloWorld) |> ignore

Additional configuration

HTTP header casing

In Suave all HTTP headers are stored in lower case inside the Suave.Http.HttpRequest object, but ASP.NET Core preserves the original casing by default.

For example if a client sends the HTTP header Content-Type: application/json with the request, then it would be stored as such in ASP.NET Core, but in lower case in Suave: content-type: application/json.

When configuring the Suave middleware you can set the preserveHttpHeaderCasing parameter to true to keep the original casing present (ASP.NET Core style):

app.UseSuave(App.helloWorld, true)

By default this setting is disabled to match existing Suave applications.

Suave config settings

Suave.AspNetCore allows you to hook a Suave web application (WebPart) into the ASP.NET Core pipeline. Anything that was configured in the SuaveConfig was web server specific and required to run Suave's own web server via startWebServer. In ASP.NET Core there are other means to configure the same settings. For more information please check out the ASP.NET Core Fundamentals.

How to build

After forking the project you should be able to run the default .NET CLI commands to build and publish the NuGet package:

dotnet restore
dotnet build
dotnet pack

License

Apache 2.0

Credits

Massive thank you to ademar and haf for creating (and open sourcing) Suave in the first place and also a big thanks to Krzysztof Cieslak for open sourcing a super early alpha version of Suave.Kestrel which was as a great kickstarter to get Suave.AspNetCore running.

Contribution

Feedback is more than welcome and pull requests get accepted!

File an issue on GitHub or contact me via https://dusted.codes/about.