-
-
Save jacqueline-homan/f7aad9e8a7c22aec8eea to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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 |
This file contains hidden or 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
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