3 people like it.
Like the snippet!
OWIN Starter Web API
A starter OWIN Web Server with Web API
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
|
open Owin
open System
open System.Collections.Generic
open System.Threading.Tasks
open System.IO
open System.Runtime.CompilerServices
open System.Web.Http
open Microsoft.Owin.Hosting
(* basic types *)
type Greeting = { text: string }
type AppFunc = Func<IDictionary<string, obj>, Task>
let awaitTask = Async.AwaitIAsyncResult >> Async.Ignore
(* Controllers *)
type GreetingController() =
inherit ApiController()
member this.Get() = { text = "Hello World "}
(* Middleware *)
type HelloWorldComponent(next: AppFunc) =
let _next = next
member this.Invoke(environment: IDictionary<string, obj>) : Task =
let response = environment.["owin.ResponseBody"] :?> Stream
use writer = new StreamWriter(response)
writer.WriteAsync("Hello!!!")
(* Extensions *)
[<Extension>]
type AppBuilderExtensions () =
[<Extension>]
static member UseHelloWorld(app: IAppBuilder) =
app.Use<HelloWorldComponent>() |> ignore
(* Startup class *)
type Startup() =
let configureWebApi = fun (app: IAppBuilder) ->
let inline (=>) a b = a, box b
let config = new HttpConfiguration()
let defaults = dict ["id" => RouteParameter.Optional]
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", defaults) |> ignore
app.UseWebApi(config)
member this.Configuration(app: IAppBuilder) =
app.Use(fun environment next ->
printfn "showing environment...."
for pair in environment.Environment do
printfn "%s : %A" pair.Key pair.Value
async {
do! awaitTask <| next.Invoke()
} |> Async.StartAsTask :> Task) |> ignore
app.Use(fun environment next ->
printfn "showing request & response...."
printfn "Request path: %s" (environment.Request.Path.ToString())
async {
do! awaitTask <| next.Invoke()
printfn "Response status code: %i" environment.Response.StatusCode
} |> Async.StartAsTask :> Task) |> ignore
configureWebApi(app) |> ignore
app.UseHelloWorld() |> ignore
(* main *)
[<EntryPoint>]
let main argv =
let uri = "http://localhost:8080"
use app = WebApp.Start<Startup>(uri)
printfn "Started!"
Console.ReadKey() |> ignore
printfn "Stopping"
0
|
namespace Owin
namespace System
namespace System.Collections
namespace System.Collections.Generic
namespace System.Threading
namespace System.Threading.Tasks
namespace System.IO
namespace System.Runtime
namespace System.Runtime.CompilerServices
namespace System.Web
namespace System.Web.Http
namespace Microsoft
namespace Microsoft.Owin
namespace Microsoft.Owin.Hosting
type Greeting =
{text: string;}
Full name: Script.Greeting
Greeting.text: string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
type AppFunc = Func<IDictionary<string,obj>,Task>
Full name: Script.AppFunc
Multiple items
type Func<'TResult> =
delegate of unit -> 'TResult
Full name: System.Func<_>
--------------------
type Func<'T,'TResult> =
delegate of 'T -> 'TResult
Full name: System.Func<_,_>
--------------------
type Func<'T1,'T2,'TResult> =
delegate of 'T1 * 'T2 -> 'TResult
Full name: System.Func<_,_,_>
--------------------
type Func<'T1,'T2,'T3,'TResult> =
delegate of 'T1 * 'T2 * 'T3 -> 'TResult
Full name: System.Func<_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 -> 'TResult
Full name: System.Func<_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 -> 'TResult
Full name: System.Func<_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Func<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15,'T16,'TResult> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 * 'T16 -> 'TResult
Full name: System.Func<_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_>
type IDictionary<'TKey,'TValue> =
member Add : key:'TKey * value:'TValue -> unit
member ContainsKey : key:'TKey -> bool
member Item : 'TKey -> 'TValue with get, set
member Keys : ICollection<'TKey>
member Remove : key:'TKey -> bool
member TryGetValue : key:'TKey * value:'TValue -> bool
member Values : ICollection<'TValue>
Full name: System.Collections.Generic.IDictionary<_,_>
type obj = Object
Full name: Microsoft.FSharp.Core.obj
Multiple items
type Task =
new : action:Action -> Task + 7 overloads
member AsyncState : obj
member ContinueWith : continuationAction:Action<Task> -> Task + 9 overloads
member CreationOptions : TaskCreationOptions
member Dispose : unit -> unit
member Exception : AggregateException
member Id : int
member IsCanceled : bool
member IsCompleted : bool
member IsFaulted : bool
...
Full name: System.Threading.Tasks.Task
--------------------
type Task<'TResult> =
inherit Task
new : function:Func<'TResult> -> Task<'TResult> + 7 overloads
member ContinueWith : continuationAction:Action<Task<'TResult>> -> Task + 9 overloads
member Result : 'TResult with get, set
static member Factory : TaskFactory<'TResult>
Full name: System.Threading.Tasks.Task<_>
--------------------
Task(action: Action) : unit
Task(action: Action, cancellationToken: Threading.CancellationToken) : unit
Task(action: Action, creationOptions: TaskCreationOptions) : unit
Task(action: Action<obj>, state: obj) : unit
Task(action: Action, cancellationToken: Threading.CancellationToken, creationOptions: TaskCreationOptions) : unit
Task(action: Action<obj>, state: obj, cancellationToken: Threading.CancellationToken) : unit
Task(action: Action<obj>, state: obj, creationOptions: TaskCreationOptions) : unit
Task(action: Action<obj>, state: obj, cancellationToken: Threading.CancellationToken, creationOptions: TaskCreationOptions) : unit
--------------------
Task(function: Func<'TResult>) : unit
Task(function: Func<'TResult>, cancellationToken: Threading.CancellationToken) : unit
Task(function: Func<'TResult>, creationOptions: TaskCreationOptions) : unit
Task(function: Func<obj,'TResult>, state: obj) : unit
Task(function: Func<'TResult>, cancellationToken: Threading.CancellationToken, creationOptions: TaskCreationOptions) : unit
Task(function: Func<obj,'TResult>, state: obj, cancellationToken: Threading.CancellationToken) : unit
Task(function: Func<obj,'TResult>, state: obj, creationOptions: TaskCreationOptions) : unit
Task(function: Func<obj,'TResult>, state: obj, cancellationToken: Threading.CancellationToken, creationOptions: TaskCreationOptions) : unit
val awaitTask : (Task -> Async<unit>)
Full name: Script.awaitTask
Multiple items
type Async
static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member AwaitTask : task:Task -> Async<unit>
static member AwaitTask : task:Task<'T> -> Async<'T>
static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
static member CancelDefaultToken : unit -> unit
static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg:'Arg1 * beginAction:('Arg1 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * beginAction:('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * arg3:'Arg3 * beginAction:('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromContinuations : callback:(('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Ignore : computation:Async<'T> -> Async<unit>
static member OnCancel : interruption:(unit -> unit) -> Async<IDisposable>
static member Parallel : computations:seq<Async<'T>> -> Async<'T []>
static member RunSynchronously : computation:Async<'T> * ?timeout:int * ?cancellationToken:CancellationToken -> 'T
static member Sleep : millisecondsDueTime:int -> Async<unit>
static member Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:CancellationToken -> Task<'T>
static member StartChild : computation:Async<'T> * ?millisecondsTimeout:int -> Async<Async<'T>>
static member StartChildAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions -> Async<Task<'T>>
static member StartImmediate : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartWithContinuations : computation:Async<'T> * continuation:('T -> unit) * exceptionContinuation:(exn -> unit) * cancellationContinuation:(OperationCanceledException -> unit) * ?cancellationToken:CancellationToken -> unit
static member SwitchToContext : syncContext:SynchronizationContext -> Async<unit>
static member SwitchToNewThread : unit -> Async<unit>
static member SwitchToThreadPool : unit -> Async<unit>
static member TryCancelled : computation:Async<'T> * compensation:(OperationCanceledException -> unit) -> Async<'T>
static member CancellationToken : Async<CancellationToken>
static member DefaultCancellationToken : CancellationToken
Full name: Microsoft.FSharp.Control.Async
--------------------
type Async<'T>
Full name: Microsoft.FSharp.Control.Async<_>
static member Async.AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member Async.Ignore : computation:Async<'T> -> Async<unit>
Multiple items
type GreetingController =
inherit ApiController
new : unit -> GreetingController
member Get : unit -> Greeting
Full name: Script.GreetingController
--------------------
new : unit -> GreetingController
Multiple items
type ApiController =
member ActionContext : HttpActionContext with get, set
member Configuration : HttpConfiguration with get, set
member ControllerContext : HttpControllerContext with get, set
member Dispose : unit -> unit
member ExecuteAsync : controllerContext:HttpControllerContext * cancellationToken:CancellationToken -> Task<HttpResponseMessage>
member ModelState : ModelStateDictionary
member Request : HttpRequestMessage with get, set
member RequestContext : HttpRequestContext with get, set
member Url : UrlHelper with get, set
member User : IPrincipal with get, set
...
Full name: System.Web.Http.ApiController
--------------------
ApiController() : unit
val this : GreetingController
member GreetingController.Get : unit -> Greeting
Full name: Script.GreetingController.Get
Multiple items
type HelloWorldComponent =
new : next:AppFunc -> HelloWorldComponent
member Invoke : environment:IDictionary<string,obj> -> Task
Full name: Script.HelloWorldComponent
--------------------
new : next:AppFunc -> HelloWorldComponent
val next : AppFunc
val this : HelloWorldComponent
member HelloWorldComponent.Invoke : environment:IDictionary<string,obj> -> Task
Full name: Script.HelloWorldComponent.Invoke
val environment : IDictionary<string,obj>
val response : Stream
type Stream =
inherit MarshalByRefObject
member BeginRead : buffer:byte[] * offset:int * count:int * callback:AsyncCallback * state:obj -> IAsyncResult
member BeginWrite : buffer:byte[] * offset:int * count:int * callback:AsyncCallback * state:obj -> IAsyncResult
member CanRead : bool
member CanSeek : bool
member CanTimeout : bool
member CanWrite : bool
member Close : unit -> unit
member CopyTo : destination:Stream -> unit + 1 overload
member Dispose : unit -> unit
member EndRead : asyncResult:IAsyncResult -> int
...
Full name: System.IO.Stream
val writer : StreamWriter
Multiple items
type StreamWriter =
inherit TextWriter
new : stream:Stream -> StreamWriter + 6 overloads
member AutoFlush : bool with get, set
member BaseStream : Stream
member Close : unit -> unit
member Encoding : Encoding
member Flush : unit -> unit
member Write : value:char -> unit + 3 overloads
static val Null : StreamWriter
Full name: System.IO.StreamWriter
--------------------
StreamWriter(stream: Stream) : unit
StreamWriter(path: string) : unit
StreamWriter(stream: Stream, encoding: Text.Encoding) : unit
StreamWriter(path: string, append: bool) : unit
StreamWriter(stream: Stream, encoding: Text.Encoding, bufferSize: int) : unit
StreamWriter(path: string, append: bool, encoding: Text.Encoding) : unit
StreamWriter(path: string, append: bool, encoding: Text.Encoding, bufferSize: int) : unit
Multiple items
type ExtensionAttribute =
inherit Attribute
new : unit -> ExtensionAttribute
Full name: System.Runtime.CompilerServices.ExtensionAttribute
--------------------
ExtensionAttribute() : unit
Multiple items
type AppBuilderExtensions =
new : unit -> AppBuilderExtensions
static member UseHelloWorld : app:IAppBuilder -> unit
Full name: Script.AppBuilderExtensions
--------------------
new : unit -> AppBuilderExtensions
static member AppBuilderExtensions.UseHelloWorld : app:IAppBuilder -> unit
Full name: Script.AppBuilderExtensions.UseHelloWorld
val app : IAppBuilder
type IAppBuilder =
member Build : returnType:Type -> obj
member New : unit -> IAppBuilder
member Properties : IDictionary<string, obj>
member Use : middleware:obj * [<ParamArray>] args:obj[] -> IAppBuilder
Full name: Owin.IAppBuilder
(extension) IAppBuilder.Use<'T>([<ParamArray>] args: obj []) : IAppBuilder
(extension) IAppBuilder.Use(handler: Func<Owin.IOwinContext,Func<Task>,Task>) : IAppBuilder
IAppBuilder.Use(middleware: obj, [<ParamArray>] args: obj []) : IAppBuilder
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
Multiple items
type Startup =
new : unit -> Startup
member Configuration : app:IAppBuilder -> unit
Full name: Script.Startup
--------------------
new : unit -> Startup
val configureWebApi : (IAppBuilder -> IAppBuilder)
val a : 'a
val b : 'b
val box : value:'T -> obj
Full name: Microsoft.FSharp.Core.Operators.box
val config : HttpConfiguration
Multiple items
type HttpConfiguration =
new : unit -> HttpConfiguration + 1 overload
member DependencyResolver : IDependencyResolver with get, set
member Dispose : unit -> unit
member EnsureInitialized : unit -> unit
member Filters : HttpFilterCollection
member Formatters : MediaTypeFormatterCollection
member IncludeErrorDetailPolicy : IncludeErrorDetailPolicy with get, set
member Initializer : Action<HttpConfiguration> with get, set
member MessageHandlers : Collection<DelegatingHandler>
member ParameterBindingRules : ParameterBindingRulesCollection with get, set
...
Full name: System.Web.Http.HttpConfiguration
--------------------
HttpConfiguration() : unit
HttpConfiguration(routes: HttpRouteCollection) : unit
val defaults : IDictionary<string,obj>
val dict : keyValuePairs:seq<'Key * 'Value> -> IDictionary<'Key,'Value> (requires equality)
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.dict
type RouteParameter =
member ToString : unit -> string
static val Optional : RouteParameter
Full name: System.Web.Http.RouteParameter
field RouteParameter.Optional
property HttpConfiguration.Routes: HttpRouteCollection
(extension) IAppBuilder.UseWebApi(configuration: HttpConfiguration) : IAppBuilder
(extension) IAppBuilder.UseWebApi(httpServer: HttpServer) : IAppBuilder
val this : Startup
Multiple items
member Startup.Configuration : app:IAppBuilder -> unit
Full name: Script.Startup.Configuration
--------------------
namespace System.Configuration
val environment : Owin.IOwinContext
val next : Func<Task>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val pair : KeyValuePair<string,obj>
property Owin.IOwinContext.Environment: IDictionary<string,obj>
property KeyValuePair.Key: string
property KeyValuePair.Value: obj
val async : AsyncBuilder
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
Func.Invoke() : Task
static member Async.StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:Threading.CancellationToken -> Task<'T>
property Owin.IOwinContext.Request: Owin.IOwinRequest
property Owin.IOwinRequest.Path: Owin.PathString
Owin.PathString.ToString() : string
property Owin.IOwinContext.Response: Owin.IOwinResponse
property Owin.IOwinResponse.StatusCode: int
static member AppBuilderExtensions.UseHelloWorld : app:IAppBuilder -> unit
Multiple items
type EntryPointAttribute =
inherit Attribute
new : unit -> EntryPointAttribute
Full name: Microsoft.FSharp.Core.EntryPointAttribute
--------------------
new : unit -> EntryPointAttribute
val main : argv:string [] -> int
Full name: Script.main
val argv : string []
val uri : string
val app : IDisposable
type WebApp =
static member Start<'TStartup> : url:string -> IDisposable + 5 overloads
Full name: Microsoft.Owin.Hosting.WebApp
WebApp.Start(options: StartOptions) : IDisposable
WebApp.Start(url: string) : IDisposable
WebApp.Start<'TStartup>(options: StartOptions) : IDisposable
WebApp.Start<'TStartup>(url: string) : IDisposable
WebApp.Start(options: StartOptions, startup: Action<IAppBuilder>) : IDisposable
WebApp.Start(url: string, startup: Action<IAppBuilder>) : IDisposable
type Console =
static member BackgroundColor : ConsoleColor with get, set
static member Beep : unit -> unit + 1 overload
static member BufferHeight : int with get, set
static member BufferWidth : int with get, set
static member CapsLock : bool
static member Clear : unit -> unit
static member CursorLeft : int with get, set
static member CursorSize : int with get, set
static member CursorTop : int with get, set
static member CursorVisible : bool with get, set
...
Full name: System.Console
Console.ReadKey() : ConsoleKeyInfo
Console.ReadKey(intercept: bool) : ConsoleKeyInfo
More information