Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Created September 29, 2014 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlexZeitler/bc178a0ff47ac200076c to your computer and use it in GitHub Desktop.
Save AlexZeitler/bc178a0ff47ac200076c to your computer and use it in GitHub Desktop.
ASP.NET Web API Owin SelfHost
open Microsoft.Owin.Hosting
open Owin
open System
open System.Net
open System.Net.Http
open System.Web.Http
type HttpRouteDefaults = { Controller : string; Id : obj }
type HomeController() =
inherit ApiController()
member this.Get() =
this.Request.CreateResponse(
HttpStatusCode.OK,
"Hello from F#")
type Startup() =
member this.Configuration(app : IAppBuilder) =
let configuration = new HttpConfiguration()
configuration.Routes.MapHttpRoute(
"DefaultAPI",
"api/{controller}/{id}",
{ Controller = "Home"; Id = RouteParameter.Optional }) |> ignore
app.UseWebApi configuration |> ignore
[<EntryPoint>]
let main argv =
let server = WebApp.Start<Startup> ("http://localhost:9001")
Console.WriteLine("Server running on http://localhost:9001")
Console.WriteLine("Press enter to exit")
Console.ReadLine() |> ignore
server.Dispose()
0
@mexx
Copy link

mexx commented Sep 29, 2014

you can get rid of .Dispose() by using use keyword, see my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment