You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Alpha] Add new route functions (...WithExtensions) (#634)
* add new endpoint routing functions to deal with asp.net extensions
* add new automated tests for basic checks of the new routing functions
* add new sample for asp.net rate limiting
* add new sample to the sln
* add documentation for the new routing functions
* add release notes placeholder
* update assembly version and remove comment
The `route`, `routef` and `subRoute` handlers are all case-insensitive. Other handlers such as `routex`, `subRoutef` or `choose` are not supported by the `Giraffe.EndpointRouting` module.
3497
3500
@@ -3525,6 +3528,39 @@ let myHandler (foo : int, bar : string) : HttpHandler =
3525
3528
3526
3529
For more information about ASP.NET Core Endpoint Routing please refer to the [official documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0).
3527
3530
3531
+
##### ALPHA :: Endpoint Routing Functions with Extensions
3532
+
3533
+
+ Note that this feature is currently in **alpha**, and major changes are expected.
3534
+
3535
+
ASP.NET Core provides several "extension" functions which can be used to fine-tune the HTTP handler behaviour. For example, there's the [Rate limiting](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) and [Output caching](https://learn.microsoft.com/en-us/aspnet/core/performance/caching/output) middlewares.
3536
+
3537
+
By using the Endpoint Routing module we can leverage this along with the `...WithExtensions` routing functions: `routeWithExtensions`, `routefWithExtensions` and `subRouteWithExtensions`.
3538
+
3539
+
Basically, whenever you decide to use a routing function variant with `...WithExtensions` you're required to provide as the first parameter a function that obbeys the `ConfigureEndpoint` type definition:
3540
+
3541
+
```fsharp
3542
+
// Note: IEndpointConventionBuilder is a shorter version of Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
3543
+
type ConfigureEndpoint = IEndpointConventionBuilder -> IEndpointConventionBuilder
route "/no-rate-limit" (text "Hello World: No Rate Limit!")
3556
+
]
3557
+
]
3558
+
```
3559
+
3560
+
In this example, we're using the ASP.NET [Rate limiting](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) middleware for the path `/rate-limit`, and not using it for `/no-rate-limit`. If you'd like to test it, check the sample at the [official repository](https://github.com/giraffe-fsharp/Giraffe) under the path *samples/RateLimiting/*. There's a `README.md` file with instructions on how to run it locally.
3561
+
3562
+
Note that for those extensions to work properly, you'll probably need to make additional changes to the server. Please check the official extension documentation page to know more about this.
3563
+
3528
3564
### TokenRouter
3529
3565
3530
3566
The `Giraffe.TokenRouter` NuGet package exposes an alternative routing `HttpHandler` which is based on top of a [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree). Several routing handlers (e.g.: `routef` and `subRoute`) have been overridden in such a way that path matching and value parsing are significantly faster than using the basic `choose` function.
Copy file name to clipboardexpand all lines: RELEASE_NOTES.md
+21
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,27 @@
1
1
Release Notes
2
2
=============
3
3
4
+
## 8.0.0-alpha-001 - 2025-02-11
5
+
6
+
With this release, we're improving the codebase a bit by fixing warnings triggered by Ionide.Analyzers, and adding .NET 9 as a target framework to the project.
7
+
8
+
Other than that, we're adding new router functions for the `EndpointRouting` module which will let the user interact with Giraffe's `ConfigureEndpoint` directly. This will let you use Asp.Net extensions directly, like rate limiting, response caching, etc. Just remember its type definition:
9
+
10
+
```fsharp
11
+
type ConfigureEndpoint = IEndpointConventionBuilder -> IEndpointConventionBuilder
12
+
```
13
+
14
+
And here we have the list of PRs related to this release:
This sample project shows how one can configure ASP.NET's built-in [rate limiting middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit?view=aspnetcore-8.0).
4
+
5
+
Notice that this rate limiting configuration is very simple, and for real life scenarios you'll need to figure out what is the best strategy to use for your server.
6
+
7
+
To make it easier to test this project locally, and see the rate limiting middleware working, you can use the `rate-limiting-test.fsx` script:
8
+
9
+
```bash
10
+
# start the server
11
+
dotnet run .
12
+
# if you want to keep using the same terminal, just start this process in the background
13
+
14
+
# then, you can use this script to test the server, and confirm that the rate-limiting
0 commit comments