From c9fd07732366691a98e3ee9bbe160872abe2e2a4 Mon Sep 17 00:00:00 2001 From: Pim Brouwers Date: Fri, 13 Dec 2024 09:26:36 -0500 Subject: [PATCH] documentation --- README.md | 3 -- docs/docs/authentication.html | 3 -- docs/docs/cross-site-request-forgery.html | 33 ++++++++++++++--- docs/docs/example-basic-rest-api.html | 12 ------- docs/docs/example-dependency-injection.html | 3 +- docs/docs/example-external-view-engine.html | 10 +++--- docs/docs/example-hello-world-mvc.html | 4 ++- docs/docs/example-hello-world.html | 14 +++++--- docs/docs/get-started.html | 15 +++++--- docs/docs/migrating-from-v4-to-v5.html | 21 +++++++---- docs/docs/request.html | 10 +++--- docs/docs/routing.html | 15 +++++--- docs/index.html | 34 +++++++++--------- documentation/authentication.md | 6 ---- documentation/cross-site-request-forgery.md | 35 +++++++++++++++++-- documentation/example-basic-rest-api.md | 12 ------- documentation/example-external-view-engine.md | 5 ++- documentation/example-hello-world-mvc.md | 2 ++ documentation/example-hello-world.md | 16 +++++---- documentation/get-started.md | 12 +++++-- documentation/migrating-from-v4-to-v5.md | 17 +++++---- documentation/routing.md | 3 ++ examples/BasicRestApi/BasicRestApi.fs | 8 +++-- .../BasicRestApiEvolved.fs | 6 ++-- .../DependencyInjection.fs | 21 +++++++---- .../ExternalViewEngine/ExternalViewEngine.fs | 4 +-- 26 files changed, 201 insertions(+), 123 deletions(-) delete mode 100644 docs/docs/example-basic-rest-api.html delete mode 100644 documentation/example-basic-rest-api.md diff --git a/README.md b/README.md index fdb174e..406c3e6 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,16 @@ open Falco open Falco.Routing open Microsoft.AspNetCore.Builder -// ^-- this import adds many useful extensions let endpoints = [ get "/" (Response.ofPlainText "Hello World!") - // ^-- associate GET / to plain text HttpHandler ] let wapp = WebApplication.Create() wapp.UseRouting() .UseFalco(endpoints) - // ^-- activate Falco endpoint source .Run() ``` diff --git a/docs/docs/authentication.html b/docs/docs/authentication.html index ab47ab3..80d592e 100644 --- a/docs/docs/authentication.html +++ b/docs/docs/authentication.html @@ -52,9 +52,6 @@

Allow only authenti

Terminate authenticated session

open Falco
-
-

Terminate authentication

-
open Falco
 
 let logOut : HttpHandler =
     let authScheme = "..."
diff --git a/docs/docs/cross-site-request-forgery.html b/docs/docs/cross-site-request-forgery.html
index 640b46d..2f08685 100644
--- a/docs/docs/cross-site-request-forgery.html
+++ b/docs/docs/cross-site-request-forgery.html
@@ -4,10 +4,35 @@
                 gtag('config', 'G-D62HSJHMNZ');

Cross-site Scripting (XSS) Attacks

Cross-site scripting attacks are extremely common since they are quite simple to carry out. Fortunately, protecting against them is as easy as performing them.

The Microsoft.AspNetCore.Antiforgery package provides the required utilities to easily protect yourself against such attacks.

-

Falco provides a few handlers via Falco.Security.Xss:

-
-

To use the Xss helpers, ensure that the Antiforgery service has been registered.

-
+

Activating Antiforgery Protection

+

To use the Falco Xsrf helpers, ensure that the Antiforgery service has been registered.

+
open Falco
+open Falco.Routing
+open Microsoft.AspNetCore.Builder
+open Microsoft.Extensions.DependencyInjection
+// ^-- this import enables antiforgery activation
+
+let endpoints =
+    [
+        // endpoints...
+    ]
+
+let bldr = WebApplication.CreateBuilder()
+
+bldr.Services
+    .AddAntiforgery()
+
+let wapp = WebApplication.Create()
+
+wapp.UseAntiforgery()
+    // ^-- activate Antiforgery before routing
+    .UseRouting()
+    .UseFalco(endpoints)
+    .Run()
+
+
+

Falco XSRF Support

+

Falco provides a few handlers via Falco.Security.Xsrf:

open Falco.Markup
 open Falco.Security
 
diff --git a/docs/docs/example-basic-rest-api.html b/docs/docs/example-basic-rest-api.html
deleted file mode 100644
index 73dbbd2..0000000
--- a/docs/docs/example-basic-rest-api.html
+++ /dev/null
@@ -1,12 +0,0 @@
-Falco - F# web toolkit for ASP.NET Core

Example - Basic REST API

-

The code for this example can be found here.

-

Creating the Application Manually

-
> dotnet new falco -o BasicRestApi
-> cd BasicRestApi
-> dotnet add package Donald
-> dotnet add package Microsoft.Data.Sqlite
-
-
© 2020-2024 Pim Brouwers & contributors.
\ No newline at end of file diff --git a/docs/docs/example-dependency-injection.html b/docs/docs/example-dependency-injection.html index 5a99601..4646ccf 100644 --- a/docs/docs/example-dependency-injection.html +++ b/docs/docs/example-dependency-injection.html @@ -50,7 +50,8 @@

Registering the Dependency

Response.ofPlainText greeting ctx) ] -wapp.UseFalco(endpoints) +wapp.UseRouting() + .UseFalco(endpoints) .Run()

Following through you can see the web server being created in two phases. The first to establish the context (i.e., logging, server configuration and dependencies). Second, freezing the final state and creating a configurable web application.

diff --git a/docs/docs/example-external-view-engine.html b/docs/docs/example-external-view-engine.html index 5152a42..942b5d5 100644 --- a/docs/docs/example-external-view-engine.html +++ b/docs/docs/example-external-view-engine.html @@ -82,7 +82,6 @@

Registering the Template Engine

open Microsoft.AspNetCore.Builder open Microsoft.Extensions.DependencyInjection - [<EntryPoint>] let main args = let bldr = WebApplication.CreateBuilder(args) @@ -91,12 +90,13 @@

Registering the Template Engine

.AddSingleton<ITemplate, ScribanTemplate>() // <-- register ITemplates implementation as a dependency |> ignore - let wapp = bldr.Build() - let endpoints = [ get "/" Pages.homepage ] - wapp.UseFalco(endpoints) + let wapp = bldr.Build() + + wapp.UseRouting() + .UseFalco(endpoints) .UseFalcoNotFound(Pages.notFound) .Run() @@ -105,4 +105,4 @@

Registering the Template Engine

Wrapping Up

Having dabbled with creating HTML applications, now let's set our sights on creating RESTful APIs.

Next: Example - Basic REST API

-
© 2020-2024 Pim Brouwers & contributors.
+
© 2020-2024 Pim Brouwers & contributors.
\ No newline at end of file diff --git a/docs/docs/example-hello-world-mvc.html b/docs/docs/example-hello-world-mvc.html index 7ef744e..d72ed33 100644 --- a/docs/docs/example-hello-world-mvc.html +++ b/docs/docs/example-hello-world-mvc.html @@ -154,8 +154,10 @@

Web Server

.UseFalco(endpoints) .UseFalcoNotFound(ErrorPage.notFound) .Run() + + 0

Wrapping Up

This example was a leap ahead from our basic hello world. But having followed this, you know understand many of the patterns you'll need to know to build end-to-end server applications with Falco. Unsurprisingly, the entire program fits inside 118 LOC. One of the magnificent benefits of writing code in F#.

Next: Example - Dependency Injection

- + \ No newline at end of file diff --git a/docs/docs/example-hello-world.html b/docs/docs/example-hello-world.html index 0f1eea6..4d111f8 100644 --- a/docs/docs/example-hello-world.html +++ b/docs/docs/example-hello-world.html @@ -10,16 +10,20 @@

Creating the Application Manually

Code Overview
open Falco
 open Falco.Routing
-open Microsoft.AspNetCore.Builder // <-- this import adds many useful extensions
-
-let wapp = WebApplication.Create()
+open Microsoft.AspNetCore.Builder
+// ^-- this import adds many useful extensions
 
 let endpoints =
     [
-        get "/" (Response.ofPlainText "Hello World!") // <-- associate GET / to plain text HttpHandler
+        get "/" (Response.ofPlainText "Hello World!")
+        // ^-- associate GET / to plain text HttpHandler
     ]
 
-wapp.UseFalco(endpoints) // <-- activate Falco endpoint source
+let wapp = WebApplication.Create()
+
+wapp.UseRouting()
+    .UseFalco(endpoints)
+    // ^-- activate Falco endpoint source
     .Run()
 

First, we open the required namespaces. Falco bring into scope the ability to activate the library and some other extension methods to make the fluent API more user-friendly.

diff --git a/docs/docs/get-started.html b/docs/docs/get-started.html index 098f2da..92158c1 100644 --- a/docs/docs/get-started.html +++ b/docs/docs/get-started.html @@ -21,14 +21,21 @@

Manually installing

Remove any *.fs files created automatically, create a new file named Program.fs and set the contents to the following:

open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
-
-let wapp = WebApplication.Create()
+// ^-- this import adds many useful extensions
 
 let endpoints =
-    [ get "/" (Response.ofPlainText "Hello World!") ]
+    [
+        get "/" (Response.ofPlainText "Hello World!")
+        // ^-- associate GET / to plain text HttpHandler
+    ]
+
+let wapp = WebApplication.Create()
 
-wapp.UseFalco(endpoints)
+wapp.UseRouting()
+    .UseFalco(endpoints)
+    // ^-- activate Falco endpoint source
     .Run()
 

Run the application:

diff --git a/docs/docs/migrating-from-v4-to-v5.html b/docs/docs/migrating-from-v4-to-v5.html index 5fcc33f..e817e8b 100644 --- a/docs/docs/migrating-from-v4-to-v5.html +++ b/docs/docs/migrating-from-v4-to-v5.html @@ -27,17 +27,22 @@

webHost expression

// Falco v5.x
 open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
 // ^-- this import adds many useful extensions
 
+let endpoints =
+    [
+        get "/" (Response.ofPlainText "Hello World!")
+        // ^-- associate GET / to plain text HttpHandler
+    ]
+
 let wapp = WebApplication.Create()
 
-wapp.Use(StaticFileExtensions.UseStaticFiles)
-    .UseFalco([
-        get "/" (Response.ofPlainText "Hello World!")
-    ])
+wapp.UseRouting()
+    .UseFalco(endpoints)
+    // ^-- activate Falco endpoint source
     .Run()
-
 
@@ -65,6 +70,7 @@

configuration expression

open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
 open Microsoft.Extensions.Configuration
 // ^-- this import adds access to Configuration
@@ -79,7 +85,8 @@ 

configuration expression

let endpoints = [] -wapp.UseFalco(endpoints) +wapp.UseRouting() + .UseFalco(endpoints) .Run()
@@ -124,5 +131,5 @@

Xss module renamed to Xsr

Crypto module removed

The Crypto module provided functionality for: random numbers, salt generation and key derivation. The code in this module was really a veneer on top of the cryptographic providers in the base library. Extracting this code into your project would be dead simple. The source is permalinked here for such purposes.

Auth module removed

-

The Auth module's functionality was ported to the Response module.

+

The Auth module functionality was ported one-to-one to the Response module.

© 2020-2024 Pim Brouwers & contributors.
\ No newline at end of file diff --git a/docs/docs/request.html b/docs/docs/request.html index 1da5298..f5d179c 100644 --- a/docs/docs/request.html +++ b/docs/docs/request.html @@ -49,7 +49,7 @@

Request Data Access

let requestData : RequestData = // From: Route | Query | Form
 
 // Retrieve primitive options
-let str : string option = requestData.TryGetString "name" 
+let str : string option = requestData.TryGetString "name"
 let flt : float option = requestData.TryGetFloat "temperature"
 
 // Retrieve primitive, or default
@@ -57,7 +57,7 @@ 

Request Data Access

let strOrDefault : string = requestData.GetString ("name", "John Doe") let flt : float = requestData.GetFloat "temperature" -// Retrieve primitive list +// Retrieve primitive list let strList : string list = requestData.GetStringList "hobbies" let grades : int list = requestData.GetInt32List "grades" @@ -179,9 +179,9 @@

JSON

LastName : string } let jsonHandler : HttpHandler = - { FirstName = "John" - LastName = "Doe" } - |> Response.ofJson + Response.ofJson { + FirstName = "John" + LastName = "Doe" } let mapJsonHandler : HttpHandler = let handleOk person : HttpHandler = diff --git a/docs/docs/routing.html b/docs/docs/routing.html index 148eb68..b3d22ca 100644 --- a/docs/docs/routing.html +++ b/docs/docs/routing.html @@ -8,6 +8,7 @@

Note: All of the following examples are fully functioning web apps.

open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
 
 let wapp = WebApplication.Create()
@@ -15,7 +16,8 @@
 let endpoints =
     [ get "/" (Response.ofPlainText "hello world") ]
 
-wapp.UseFalco(endpoints)
+wapp.UseRouting()
+    .UseFalco(endpoints)
     .Run()
 

The preceding example includes a single HttpEndpoint:

@@ -30,6 +32,7 @@

The following example shows a more sophisticated HttpEndpoint:

open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
 
 let wapp = WebApplication.Create()
@@ -43,7 +46,8 @@
             Response.ofPlainText message ctx)
     ]
 
-wapp.UseFalco(endpoints)
+wapp.UseRouting()
+    .UseFalco(endpoints)
     .Run()
 

The string /hello/{name:alpha} is a route template. It is used to configure how the endpoint is matched. In this case, the template matches:

@@ -62,6 +66,7 @@

An alternative way to express the HttEndpoint above is seen below.

open Falco
+open Falco.Routing
 open Microsoft.AspNetCore.Builder
 
 let wapp = WebApplication.Create()
@@ -73,7 +78,8 @@
 let endpoints =
     [ mapGet "/hello/{name:alpha}" (fun route -> r.GetString "name") greetingHandler ]
 
-wapp.UseFalco(endpoints)
+wapp.UseRouting()
+    .UseFalco(endpoints)
     .Run()
 

Multi-method Endpoints

@@ -99,7 +105,8 @@

Multi-method Endpoints

POST, Response.ofEmpty ] ] -wapp.UseFalco(endpoints) +wapp.UseRouting() + .UseFalco(endpoints) .Run()

Next: Writing responses

diff --git a/docs/index.html b/docs/index.html index 5885da8..90f19b6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -8,35 +8,35 @@ open Falco.Routing open Microsoft.AspNetCore.Builder -let wapp = WebApplication.Create() - let endpoints = - // associate GET / to plain text HttpHandler - [ get "/" (Response.ofPlainText "Hello World!") ] + [ + get "/" (Response.ofPlainText "Hello World!") + ] + +let wapp = WebApplication.Create() -// activate Falco endpoint source -wapp.UseFalco(endpoints) +wapp.UseRouting() + .UseFalco(endpoints) .Run()

Falco is a toolkit for building fast and functional-first web applications using F#. You can think of it as minimal API on steroids.

Key Features

Design Goals

@@ -47,8 +47,8 @@

Learn

Community Projects

@@ -70,7 +70,7 @@

Videos

Contribute

Thank you for considering contributing to Falco, and to those who have already contributed! We appreciate (and actively resolve) PRs of all shapes and sizes.

We kindly ask that before submitting a pull request, you first submit an issue or open a discussion.

-

If functionality is added to the API, or changed, please kindly update the relevant document. Unit tests must also be added and/or updated before a pull request can be successfully merged.

+

If functionality is added to the API, or changed, please kindly update the relevant document. Unit tests must also be added and/or updated before a pull request can be successfully merged.

Only pull requests which pass all build checks and comply with the general coding guidelines can be approved.

If you have any further questions, submit an issue or open a discussion or reach out on Twitter.

Why "Falco"?

diff --git a/documentation/authentication.md b/documentation/authentication.md index afdd99c..a09c258 100644 --- a/documentation/authentication.md +++ b/documentation/authentication.md @@ -66,12 +66,6 @@ let secureResourceHandler : HttpHandler = ### Terminate authenticated session -```fsharp -open Falco -``` - -## Terminate authentication - ```fsharp open Falco diff --git a/documentation/cross-site-request-forgery.md b/documentation/cross-site-request-forgery.md index 5c984bf..29bc656 100644 --- a/documentation/cross-site-request-forgery.md +++ b/documentation/cross-site-request-forgery.md @@ -4,9 +4,40 @@ Cross-site scripting attacks are extremely common since they are quite simple to The [Microsoft.AspNetCore.Antiforgery](https://docs.microsoft.com/en-us/aspnet/core/security/anti-request-forgery) package provides the required utilities to easily protect yourself against such attacks. -Falco provides a few handlers via `Falco.Security.Xss`: +## Activating Antiforgery Protection -> To use the Xss helpers, ensure that the `Antiforgery` service has been registered. +To use the Falco Xsrf helpers, ensure that the `Antiforgery` service has been [registered](https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery). + +```fsharp +open Falco +open Falco.Routing +open Microsoft.AspNetCore.Builder +open Microsoft.Extensions.DependencyInjection +// ^-- this import enables antiforgery activation + +let endpoints = + [ + // endpoints... + ] + +let bldr = WebApplication.CreateBuilder() + +bldr.Services + .AddAntiforgery() + +let wapp = WebApplication.Create() + +wapp.UseAntiforgery() + // ^-- activate Antiforgery before routing + .UseRouting() + .UseFalco(endpoints) + .Run() + +``` + +## Falco XSRF Support + +Falco provides a few handlers via `Falco.Security.Xsrf`: ```fsharp open Falco.Markup diff --git a/documentation/example-basic-rest-api.md b/documentation/example-basic-rest-api.md deleted file mode 100644 index 9cb5b79..0000000 --- a/documentation/example-basic-rest-api.md +++ /dev/null @@ -1,12 +0,0 @@ -# Example - Basic REST API - -The code for this example can be found [here](https://github.com/pimbrouwers/Falco/tree/master/examples/BasicRestApi). - -## Creating the Application Manually - -```shell -> dotnet new falco -o BasicRestApi -> cd BasicRestApi -> dotnet add package Donald -> dotnet add package Microsoft.Data.Sqlite -``` \ No newline at end of file diff --git a/documentation/example-external-view-engine.md b/documentation/example-external-view-engine.md index 9997e09..5639a3e 100644 --- a/documentation/example-external-view-engine.md +++ b/documentation/example-external-view-engine.md @@ -101,7 +101,6 @@ open Falco.Routing open Microsoft.AspNetCore.Builder open Microsoft.Extensions.DependencyInjection - [] let main args = let bldr = WebApplication.CreateBuilder(args) @@ -110,11 +109,11 @@ let main args = .AddSingleton() // <-- register ITemplates implementation as a dependency |> ignore - let wapp = bldr.Build() - let endpoints = [ get "/" Pages.homepage ] + let wapp = bldr.Build() + wapp.UseRouting() .UseFalco(endpoints) .UseFalcoNotFound(Pages.notFound) diff --git a/documentation/example-hello-world-mvc.md b/documentation/example-hello-world-mvc.md index 982f8a0..f976a4d 100644 --- a/documentation/example-hello-world-mvc.md +++ b/documentation/example-hello-world-mvc.md @@ -193,6 +193,8 @@ module Program = .UseFalco(endpoints) .UseFalcoNotFound(ErrorPage.notFound) .Run() + + 0 ``` ## Wrapping Up diff --git a/documentation/example-hello-world.md b/documentation/example-hello-world.md index 3cc36a8..44df7d0 100644 --- a/documentation/example-hello-world.md +++ b/documentation/example-hello-world.md @@ -15,17 +15,20 @@ The code for this example can be found [here](https://github.com/pimbrouwers/Fal ```fsharp open Falco open Falco.Routing -open Microsoft.AspNetCore.Builder // <-- this import adds many useful extensions - -let wapp = WebApplication.Create() +open Microsoft.AspNetCore.Builder +// ^-- this import adds many useful extensions let endpoints = [ - get "/" (Response.ofPlainText "Hello World!") // <-- associate GET / to plain text HttpHandler + get "/" (Response.ofPlainText "Hello World!") + // ^-- associate GET / to plain text HttpHandler ] +let wapp = WebApplication.Create() + wapp.UseRouting() - .UseFalco(endpoints) // <-- activate Falco endpoint source + .UseFalco(endpoints) + // ^-- activate Falco endpoint source .Run() ``` @@ -35,8 +38,7 @@ First, we open the required namespaces. `Falco` bring into scope the ability to After creating the web application, we: -- Activate Falco using `wapp.UseRouting() - .UseFalco()`. This enables us to create endpoints. +- Activate Falco using `wapp.UseFalco()`. This enables us to create endpoints. - Register `GET /` endpoint to a handler which responds with "hello world". - Run the app. diff --git a/documentation/get-started.md b/documentation/get-started.md index 0a6cbd1..0d40a3d 100644 --- a/documentation/get-started.md +++ b/documentation/get-started.md @@ -35,15 +35,21 @@ Remove any `*.fs` files created automatically, create a new file named `Program. ```fsharp open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder - -let wapp = WebApplication.Create() +// ^-- this import adds many useful extensions let endpoints = - [ get "/" (Response.ofPlainText "Hello World!") ] + [ + get "/" (Response.ofPlainText "Hello World!") + // ^-- associate GET / to plain text HttpHandler + ] + +let wapp = WebApplication.Create() wapp.UseRouting() .UseFalco(endpoints) + // ^-- activate Falco endpoint source .Run() ``` diff --git a/documentation/migrating-from-v4-to-v5.md b/documentation/migrating-from-v4-to-v5.md index 1e8818b..cb1165a 100644 --- a/documentation/migrating-from-v4-to-v5.md +++ b/documentation/migrating-from-v4-to-v5.md @@ -35,18 +35,22 @@ webHost args { ```fsharp // Falco v5.x open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder // ^-- this import adds many useful extensions +let endpoints = + [ + get "/" (Response.ofPlainText "Hello World!") + // ^-- associate GET / to plain text HttpHandler + ] + let wapp = WebApplication.Create() -wapp.Use(StaticFileExtensions.UseStaticFiles) - .UseRouting() // <-- required to enable endpoint routing - .UseFalco([ - get "/" (Response.ofPlainText "Hello World!") - ]) +wapp.UseRouting() + .UseFalco(endpoints) + // ^-- activate Falco endpoint source .Run() - ``` @@ -82,6 +86,7 @@ webHost [||] { ```fsharp open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder open Microsoft.Extensions.Configuration // ^-- this import adds access to Configuration diff --git a/documentation/routing.md b/documentation/routing.md index 04e2e3d..eee30b6 100644 --- a/documentation/routing.md +++ b/documentation/routing.md @@ -8,6 +8,7 @@ Bearing this in mind, routing can practically be represented by a list of these ```fsharp open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder let wapp = WebApplication.Create() @@ -30,6 +31,7 @@ The following example shows a more sophisticated `HttpEndpoint`: ```fsharp open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder let wapp = WebApplication.Create() @@ -63,6 +65,7 @@ An alternative way to express the `HttEndpoint` above is seen below. ```fsharp open Falco +open Falco.Routing open Microsoft.AspNetCore.Builder let wapp = WebApplication.Create() diff --git a/examples/BasicRestApi/BasicRestApi.fs b/examples/BasicRestApi/BasicRestApi.fs index 79a46f9..b39fcb0 100644 --- a/examples/BasicRestApi/BasicRestApi.fs +++ b/examples/BasicRestApi/BasicRestApi.fs @@ -1,12 +1,14 @@ namespace BasicRestApi open System.Data -open Donald // <-- external package that makes using databases simpler +open Donald +// ^-- external package that makes using databases simpler open Falco open Falco.Routing open Microsoft.AspNetCore.Builder open Microsoft.Extensions.DependencyInjection -open Microsoft.Data.Sqlite // <-- a very useful Microsoft package +open Microsoft.Data.Sqlite +// ^-- a very useful Microsoft package type Error = { Code : string @@ -153,6 +155,7 @@ module Program = initializeDatabase dbConnectionFactory bldr.Services + .AddAntiforgery() .AddSingleton(dbConnectionFactory) .AddSingleton, UserStore>() |> ignore @@ -163,6 +166,7 @@ module Program = wapp.UseIf(isDevelopment, DeveloperExceptionPageExtensions.UseDeveloperExceptionPage) .UseIf(not(isDevelopment), FalcoExtensions.UseFalcoExceptionHandler ErrorPage.serverException) + .UseAntiforgery() .UseRouting() .UseFalco(endpoints) .Run() diff --git a/examples/BasicRestApiEvolved/BasicRestApiEvolved.fs b/examples/BasicRestApiEvolved/BasicRestApiEvolved.fs index 2d0ecb9..bf48f4f 100644 --- a/examples/BasicRestApiEvolved/BasicRestApiEvolved.fs +++ b/examples/BasicRestApiEvolved/BasicRestApiEvolved.fs @@ -3,14 +3,16 @@ namespace BasicRestApi open System open System.Data open System.Threading.Tasks -open Donald // <-- external package that makes using databases simpler +open Donald +// ^-- external package that makes using databases simpler open Falco open Falco.Routing open Microsoft.AspNetCore.Builder open Microsoft.Extensions.Configuration open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Logging -open Microsoft.Data.Sqlite // <-- a very useful Microsoft package +open Microsoft.Data.Sqlite +// ^-- a very useful Microsoft package type Error = { Code : string diff --git a/examples/DependencyInjection/DependencyInjection.fs b/examples/DependencyInjection/DependencyInjection.fs index 1184162..f68bb9f 100644 --- a/examples/DependencyInjection/DependencyInjection.fs +++ b/examples/DependencyInjection/DependencyInjection.fs @@ -1,7 +1,7 @@ open Falco open Falco.Routing open Microsoft.AspNetCore.Builder -open Microsoft.Extensions.DependencyInjection // <-- this import adds DI capabilities +open Microsoft.Extensions.DependencyInjection type IGreeter = abstract member Greet : name : string -> string @@ -11,24 +11,31 @@ type FriendlyGreeter() = member _.Greet(name : string) = $"Hello {name} 😀" -let bldr = WebApplication.CreateBuilder() // <-- create a configurable web application builder +let bldr = WebApplication.CreateBuilder() +// ^-- create a configurable web application builder bldr.Services - .AddSingleton() // <-- register the greeter as singleton in the container + .AddSingleton() + // ^-- register the greeter as singleton in the container |> ignore -let wapp = bldr.Build() // <-- manifest our WebApplication - let endpoints = [ mapGet "/{name?}" (fun r -> r?name.AsStringNonEmpty("world")) (fun name ctx -> - let greeter = ctx.Plug() // <-- access our dependency from the container - let greeting = greeter.Greet(name) // <-- invoke our greeter.Greet(name) method + let greeter = ctx.Plug() + // ^-- access our dependency from the container + + let greeting = greeter.Greet(name) + // ^-- invoke our greeter.Greet(name) method + Response.ofPlainText greeting ctx) ] +let wapp = bldr.Build() +// ^-- manifest our WebApplication + wapp.UseRouting() .UseFalco(endpoints) .Run() diff --git a/examples/ExternalViewEngine/ExternalViewEngine.fs b/examples/ExternalViewEngine/ExternalViewEngine.fs index bf257e1..8ca722c 100644 --- a/examples/ExternalViewEngine/ExternalViewEngine.fs +++ b/examples/ExternalViewEngine/ExternalViewEngine.fs @@ -61,11 +61,11 @@ let main args = .AddSingleton() // <-- register ITemplates implementation as a dependency |> ignore - let wapp = bldr.Build() - let endpoints = [ get "/" Pages.homepage ] + let wapp = bldr.Build() + wapp.UseRouting() .UseFalco(endpoints) .UseFalcoNotFound(Pages.notFound)