4 people like it.

Minimal AspNetCore web server

Demonstrates the minimum references required to run an AspNet.Core web server in F# script

 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: 
(* creates a web server in F# script *)

#I @"C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.4"
#r "Microsoft.AspNetCore"
#r "Microsoft.AspNetCore.Routing"
#r "Microsoft.AspNetCore.Http.Abstractions"
#r "Microsoft.AspNetCore.Hosting"
#r "Microsoft.AspNetCore.Diagnostics"
#r "Microsoft.AspNetCore.Hosting.Abstractions"
#r "Microsoft.Extensions.DependencyInjection.Abstractions"
#r "Microsoft.Extensions.Hosting"
#r "Microsoft.Extensions.Hosting.Abstractions"

open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Http

type Startup() =

    member _.ConfigureServices(services: IServiceCollection) = ()

    member _.Configure(app: IApplicationBuilder, env: IHostEnvironment) =
        if env.IsDevelopment() then
            app.UseDeveloperExceptionPage() |> ignore

        app
            .UseRouting()
            .UseEndpoints(fun endpoints ->
                endpoints.MapGet("/", (fun context -> context.Response.WriteAsync("Hello World!")))
                |> ignore)
        |> ignore


let createHostBuilder (args: string []) =
    Host
        .CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(fun webBuilder -> webBuilder.UseStartup<Startup>() |> ignore)

let main args = createHostBuilder(args).Build().Run()

main [||]
namespace Microsoft
Multiple items
type Startup =
  new : unit -> Startup
  member Configure : app:'a * env:'b -> unit
  member ConfigureServices : services:'c -> unit

--------------------
new : unit -> Startup
val services : 'c
val app : 'a
val env : 'b
val ignore : value:'T -> unit
val createHostBuilder : args:string [] -> 'a
val args : string []
Multiple items
val string : value:'T -> string

--------------------
type string = System.String
val main : args:string [] -> 'a
Raw view Test code New version

More information

Link:http://fssnip.net/82a
Posted:2 years ago
Author:Chui Tey
Tags: aspnet , web