Created
September 29, 2014 18:40
-
-
Save AlexZeitler/bc178a0ff47ac200076c to your computer and use it in GitHub Desktop.
ASP.NET Web API Owin SelfHost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can get rid of
.Dispose()
by usinguse
keyword, see my fork.