Skip to content

Commit 55474ae

Browse files
Add docs
1 parent 37eda71 commit 55474ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Endpoint Routing
3+
category: explanation
4+
menu_order: 8
5+
---
6+
7+
# Endpoint Routing
8+
9+
Saturn from version `0.15` supports [ASP.NET Endpoint Routing](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-3.1) additionally to custom routing implementation provided by Giraffe. The main difference between old routing and new one is that Endpoint Routing assumes total separation of routing from behavior - it works by statically defining list of all possible routes on startup of application. This impacts design of some of our Saturn abstractions, and means new routing is not 100% compatible with old one. On the bright side, theoretically, Endpoint Routing should provide noticeable performance boost, and in the future it will allow for better ecosystem integration.
10+
11+
> Currently endpoint routing API is treated as an experimental API - it's subject to changes.
12+
13+
To use Endpoint Routing you need to open `Saturn.Endpoint` namespace - this will override known `router` and `controller` Computation Expressions with their Endpoint Routing versions. In `application` CE instead of using `use_router` operation you should use `use_endpoint_router` operation. For many simple applications this may be enough to get things working - we've been trying to keep API as compatible as possible.
14+
15+
However there are differences:
16+
17+
* With Endpoint Routing `router` and `controller` computation expressions are not transformed to `HttpHandler` but rather to `Endpoint list`. This has a huge impact on composability of those abstractions - you can't do things like `myHttpHandler >=> router { ... }` any more. Such code should be replaced with `plug/pipe_through` functionality in both `router` and `controller`. `Endpoint list` can basically be used in 2 places - in `forward` operation in `router` and `use_endpoint_router` in `application`.
18+
* Lack of `subroutef` in Giraffe-EndpointRouting - beacuse EndpointRouting needs to have all possible route templates at the application startup it's really hard to emulate some of previous Giraffe's routing composibility capabilities. From Saturn point of view this created 2 major changes:
19+
- there's no `forwardf` in `router` CE anymore - it should be replaced with set of `getf/postf/putf ... ` operations in child router.
20+
- `subController` in `controller` CE doesn't work well in Endpoint Routing - you can use as subcontrollers only old, HttpHandler based controllers (even if you parent controller is Endpoint Routing controller). In `Saturn.Endpoint` we provide additonal `subcontroller` CE - it's an alias to old `controller` CE
21+
* Lack of `case_insensitive` in `router` and `controller` - with Endpoint Routing all routes are case insensitive by default and there's no easy way to change it
22+
* Lack of `not_found_handler` in `router` and `controller` - as Endpoint Routing creates global table of routing having scoped not-found handlers is really tricky. Use built-in ways of handle 404 in ASP.NET (such as `UseDeveloperExceptionPage`)
23+
* Unlike Giraffe routing, Endpoint Routing doesn't ensure order of routing checks - this shouldn't be a problem in most cases, but I can imagine some edge cases in which this would matter.
24+
25+
In general, to reiterate - Endpoint Routing API in Giraffe/Saturn is still experimental. However, it probably is a future of Giraffe/Saturn so if possible please check if your applications can move to the Endpoint Routing API, and try it out. It's important for everyone involved to get feedback on this new routing engine.

src/Saturn/RouterEndpoint.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ module Router =
216216
member __.PatchF(state, path, action) : RouterState =
217217
addRouteF RouteType.Patch state path action
218218

219-
///Forwards calls to different `Endpoint`. Modifies the `HttpRequest.Path` to allow subrouting.
219+
///Forwards calls to different `Endpoint`.
220220
[<CustomOperation("forward")>]
221221
member __.Forward(state, path : string, action : Endpoint) : RouterState =
222222
addForward state path [action]
223223

224-
///Forwards calls to different list of `Endpoint`. Modifies the `HttpRequest.Path` to allow subrouting.
224+
///Forwards calls to different list of `Endpoint`.
225225
member __.Forward(state, path : string, actions : Endpoint list) : RouterState =
226226
addForward state path actions
227227

0 commit comments

Comments
 (0)