Skip to content

Instantly share code, notes, and snippets.

@jacqueline-homan
Forked from mikehadlow/Program.fs
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqueline-homan/f7aad9e8a7c22aec8eea to your computer and use it in GitHub Desktop.
Save jacqueline-homan/f7aad9e8a7c22aec8eea to your computer and use it in GitHub Desktop.
open System
open Microsoft.Owin.Hosting
[<EntryPoint>]
let main argv =
let baseAddress = "http://localhost:8888"
use application = WebApp.Start<Startup.Startup>(baseAddress)
Console.WriteLine("Server running on {0}", baseAddress)
Console.WriteLine("hit <enter> to stop")
Console.ReadLine() |> ignore
0 // return an integer exit code
module Startup
open Owin
open Microsoft.Owin
open System
open System.IO
open System.Threading.Tasks
let transform (input: string) =
sprintf "%s transformed" input
type public Startup() =
let handleOwinContext (context:IOwinContext) =
use writer = new StreamWriter(context.Response.Body)
match context.Request.Method with
| "POST" ->
use reader = new StreamReader(context.Request.Body)
writer.Write(transform(reader.ReadToEnd()))
| _ ->
context.Response.StatusCode <- 400
writer.Write("Only POST")
let owinHandler = fun (context:IOwinContext) (_:Func<Task>) ->
handleOwinContext context;
Task.FromResult(null) :> Task
member x.Configuration (app:IAppBuilder) = app.Use(owinHandler) |> ignore
let private Main () =
printfn "%s" (transform "some input")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment