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.
Current release information
The current version has a dependency on Suave 2.0.2, and supports Suave's web request handling and the
If you wish to use web sockets in ASP.NET Core please check out the ASP.NET Core Web Sockets project.
|.NET Standard||>= 1.6|
|Full .NET||>= 4.6|
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
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:
When configuring the Suave middleware you can set the
preserveHttpHeaderCasing parameter to
true to keep the original casing present (ASP.NET Core style):
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
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.
Feedback is more than welcome and pull requests get accepted!
File an issue on GitHub or contact me via https://dusted.codes/about.