Last active
September 20, 2025 07:26
-
-
Save matarillo/a52dd86504c82bb32292e6cc6c3b2ce8 to your computer and use it in GitHub Desktop.
compare giraffe with falco
This file contains hidden or 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
| open Falco | |
| open Falco.Routing | |
| open Microsoft.AspNetCore.Builder | |
| let endpoints = | |
| [ get "/weather" WeatherForecast.getRandom | |
| get "/" (Response.ofPlainText "Hello World!") ] | |
| [<EntryPoint>] | |
| let main args = | |
| let app = WebApplication.Create() | |
| app.UseRouting().UseFalco(endpoints) |> ignore | |
| app.Run(Response.withStatusCode 404 >> Response.ofPlainText "Not found") | |
| 0 |
This file contains hidden or 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
| module WeatherForecast | |
| open System | |
| open System.Text.Json | |
| open Falco | |
| type WeatherForecast = | |
| { Date: DateTime | |
| TemperatureC: int | |
| Summary: string } | |
| member this.TemperatureF = 32.0 + float this.TemperatureC / 0.5556 | |
| let private summaries = | |
| [| "Freezing" | |
| "Bracing" | |
| "Chilly" | |
| "Cool" | |
| "Mild" | |
| "Warm" | |
| "Balmy" | |
| "Hot" | |
| "Sweltering" | |
| "Scorching" |] | |
| let private options = | |
| let options = JsonSerializerOptions() | |
| options.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase | |
| options | |
| let getRandom: HttpHandler = | |
| let rng = Random() | |
| let weathers = | |
| [| for index in 0..4 -> | |
| { Date = DateTime.Now.AddDays(float index) | |
| TemperatureC = rng.Next(-20, 55) | |
| Summary = summaries.[rng.Next(summaries.Length)] } |] | |
| Response.ofJsonOptions options weathers |
This file contains hidden or 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
| open Microsoft.AspNetCore.Builder | |
| open Microsoft.Extensions.Hosting | |
| open Giraffe | |
| let webApp = | |
| choose | |
| [ route "/weather" >=> WeatherForecast.getRandom | |
| route "/" >=> text "Hello World" ] | |
| [<EntryPoint>] | |
| let main args = | |
| let builder = WebApplication.CreateBuilder() | |
| builder.Services.AddGiraffe() |> ignore | |
| let app = builder.Build() | |
| app.UseGiraffe webApp | |
| app.Run() | |
| 0 |
This file contains hidden or 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
| module WeatherForecast | |
| open Giraffe | |
| open System | |
| type WeatherForecast = | |
| { Date: DateTime | |
| TemperatureC: int | |
| Summary: string } | |
| member this.TemperatureF = 32.0 + float this.TemperatureC / 0.5556 | |
| let private summaries = | |
| [| "Freezing" | |
| "Bracing" | |
| "Chilly" | |
| "Cool" | |
| "Mild" | |
| "Warm" | |
| "Balmy" | |
| "Hot" | |
| "Sweltering" | |
| "Scorching" |] | |
| let getRandom: HttpFunc -> HttpFunc = | |
| let rng = Random() | |
| let weathers = | |
| [| for index in 0..4 -> | |
| { Date = DateTime.Now.AddDays(float index) | |
| TemperatureC = rng.Next(-20, 55) | |
| Summary = summaries.[rng.Next(summaries.Length)] } |] | |
| json weathers |
This file contains hidden or 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
| open Microsoft.AspNetCore.Builder | |
| open Microsoft.Extensions.Hosting | |
| open Giraffe | |
| open Giraffe.EndpointRouting | |
| let endpointsList = | |
| [ GET | |
| [ route "/weather" WeatherForecast.getRandom | |
| route "/" (text "Hello World!") ] ] | |
| [<EntryPoint>] | |
| let main (args: string[]) = | |
| let builder = WebApplication.CreateBuilder args | |
| builder.Services.AddGiraffe() |> ignore | |
| let app = builder.Build() | |
| app.UseRouting().UseEndpoints(fun e -> e.MapGiraffeEndpoints endpointsList) | |
| |> ignore | |
| app.Run() | |
| 0 |
This file contains hidden or 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
| module WeatherForecast | |
| open System | |
| open Giraffe | |
| type WeatherForecast = | |
| { Date: DateTime | |
| TemperatureC: int | |
| Summary: string } | |
| member this.TemperatureF = 32.0 + float this.TemperatureC / 0.5556 | |
| let private summaries = | |
| [| "Freezing" | |
| "Bracing" | |
| "Chilly" | |
| "Cool" | |
| "Mild" | |
| "Warm" | |
| "Balmy" | |
| "Hot" | |
| "Sweltering" | |
| "Scorching" |] | |
| let getRandom: HttpHandler = | |
| let rng = Random() | |
| fun next ctx -> | |
| let weathers = | |
| [| for index in 0..4 -> | |
| { Date = DateTime.Now.AddDays(float index) | |
| TemperatureC = rng.Next(-20, 55) | |
| Summary = summaries.[rng.Next(summaries.Length)] } |] | |
| json weathers next ctx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment