This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Hosting Nancy with Suave.IO
Daniel J. Summers edited this page Jan 2, 2017
·
10 revisions
Nancy is a great choice for applications that want to run a lightweight HTTP server without the overhead of IIS. To do this, take the following steps.
Create your paket.references file for a new F# Console App:
FSharp.Core
Nancy.Owin
Run paket install
and then; add an implementation to your console app:
namespace Suave.NancyFx
open Suave.Web
open Suave.Owin
open Nancy
open Nancy.Owin
type App() as x =
inherit NancyModule()
do
x.Get.["/"] <- fun _ -> "Hello World, from NancyFx on Suave!" :> obj
x.Get.["/fsharp"] <- fun _ -> "I can into F#" :> obj
x.Get.["/json"] <- fun _ -> x.Response.AsJson([ "Test" ]) :> obj
x.Get.["/complex"] <- fun _ ->
let response = x.Response.AsJson(["This is my Response"])
response.ContentType <- "application/json"
response.Headers.Add("Funky-Header", "Funky-Header-Value")
response :> obj
module Program =
[<EntryPoint>]
let main argv =
let opts = new NancyOptions()
let app = OwinApp.ofMidFunc "/" (NancyMiddleware.UseNancy(opts))
startWebServer defaultConfig app
0
Run your app!
$ curl -i http://localhost:8083
HTTP/1.1 200 OK
Server: Suave/0.30.0.0 (http://suave.io)
Date: Mon, 31 Aug 2015 08:23:25 GMT
Content-Type: text/html
Content-Length: 35
Hello World, from NancyFx on Suave!
using Suave;
using Nancy;
using Nancy.Owin;
namespace Suave.NancyFx
{
public class SampleModule : NancyModule
{
public SampleModule()
{
Get["/"] = _ => "Hello World!";
}
}
public class Program
{
public static int Main(string[] args)
{
var opts = new NancyOptions();
var app = Suave.Owin.OwinAppModule.OfMidFunc("/", NancyMiddleware.UseNancy(opts));
Web.startWebServer(Web.defaultConfig, app);
return 0;
}
}
}
- Introduction
- Exploring the Nancy module
- Routing
- Taking a look at the DynamicDictionary
- Async
- View Engines
- Using Models
- Managing static content
- Authentication
- Lifecycle of a Nancy Application
- Bootstrapper
- Adding a custom FavIcon
- Diagnostics
- Generating a custom error page
- Localization
- SSL Behind Proxy
- Testing your application
- The cryptography helpers
- Validation
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with Suave.IO
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Hosting Nancy with FastCgi
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Running Nancy on your Raspberry Pi
- Running Nancy with ASP.NET Core 3.1