Created
July 10, 2014 18:40
-
-
Save panesofglass/7cd866c669023d23e014 to your computer and use it in GitHub Desktop.
Taliesin Sample
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
namespace FSharpWeb4 | |
open Owin | |
open Microsoft.Owin | |
open System | |
open System.Net | |
open System.Net.Http | |
open System.Web | |
open Dyfrig | |
open Taliesin | |
type Resources = Home | |
with | |
interface IUriRouteTemplate with | |
member x.UriTemplate = "/" | |
module App = | |
let makeHttpHandler statusCode (data: byte[]) = | |
let handler (request: HttpRequestMessage) = | |
let content = new ByteArrayContent(data) | |
content.Headers.ContentLength <- Nullable data.LongLength | |
content.Headers.ContentType <- Headers.MediaTypeHeaderValue("text/plain") | |
new HttpResponseMessage(statusCode, Content = content, RequestMessage = request) | |
|> async.Return | |
Dyfrig.SystemNetHttpAdapter.fromAsyncSystemNetHttp handler | |
let spec = RouteLeaf(Home, [GET(makeHttpHandler HttpStatusCode.OK "Hello from Taliesin!"B)]) | |
type Startup() = | |
member x.Configuration(app: IAppBuilder) = | |
let taliesin = new ResourceManager<Resources>() | |
let subscription = taliesin.Start(App.spec) | |
app.Use(fun _ -> taliesin.Invoke) |> ignore | |
type Global() = | |
inherit System.Web.HttpApplication() | |
[<assembly:OwinStartup(typeof<Startup>)>] | |
do () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment