Skip to content

Instantly share code, notes, and snippets.

@teyc
Last active April 11, 2021 22:38
Show Gist options
  • Save teyc/d8632e76d44aaf8fd804741edf660b7f to your computer and use it in GitHub Desktop.
Save teyc/d8632e76d44aaf8fd804741edf660b7f to your computer and use it in GitHub Desktop.
F# snippets
(* 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() =
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
member _.ConfigureServices(services: IServiceCollection) = ()
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
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 [||]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment