Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,6 @@ let fooHandler (first : string,

let webApp =
choose [
// Named parameter example:
routef "/pet/%i:petId" (fun (petId: int) -> text (sprintf "PetId: %i" petId))
// Classic usage:
routef "/foo/%s/%s/%i" fooHandler
routef "/bar/%O" (fun guid -> text (guid.ToString()))
Expand All @@ -1104,7 +1102,7 @@ let webApp =

The `routef` http handler takes two parameters - a format string and an `HttpHandler` function.

The format string supports the following format chars, and now also supports **named parameters** using the syntax `%c:name` (e.g. `%i:petId`):
The format string supports the following format chars:

| Format Char | Type |
| ----------- | ---- |
Expand All @@ -1117,7 +1115,11 @@ The format string supports the following format chars, and now also supports **n
| `%O` | `Guid` (including short GUIDs*) |
| `%u` | `uint64` (formatted as a short ID*) |

**Named parameters**: You can use `%c:name` to assign a name to a route parameter, which is especially useful for OpenAPI/Swagger documentation and for clarity. For example, `routef "/pet/%i:petId"` will match `/pet/42` and bind `petId` to `42`.
**Named parameters**: When using ASP.NET Core’s [Endpoint Routing](#endpoint-routing) with Giraffe, you can use `%<type>:<name>` (e.g., `%i:petId`) to assign a name to a route parameter, which is especially useful for OpenAPI/Swagger documentation and for clarity.

For example, the route `routef "/pet/%i:petId"` will match `/pet/42` and bind `42` to `petId`.

If you'd like to see an example, check the [EndpointRoutingApp sample](https://github.com/giraffe-fsharp/Giraffe/blob/master/samples/EndpointRoutingApp/Program.fs) at the official repository.

*) Please note that the `%O` and `%u` format characters also support URL friendly short GUIDs and IDs.

Expand Down