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
Enhance routef support for named parameters and improve documentation (#656)
* fix: enhance getConstraint function to handle optional name parameter
* docs: add handler for petId endpoint to sample
* test: add routef test for named parameter in pet endpoint
* docs: add support for named parameters in routef documentation
* Apply fantomas
* Add more unit tests
* Fix formatting
* Update tests/Giraffe.Tests/EndpointRoutingTests.fs
* Fix formatting and add new test scenarios
---------
Co-authored-by: Vinícius Gajo <[email protected]>
Co-authored-by: 64J0 <[email protected]>
routef "/bar/%O" (fun guid -> text (guid.ToString()))
1094
1097
@@ -1099,7 +1102,7 @@ let webApp =
1099
1102
1100
1103
The `routef` http handler takes two parameters - a format string and an `HttpHandler` function.
1101
1104
1102
-
The format string supports the following format chars:
1105
+
The format string supports the following format chars, and now also supports **named parameters** using the syntax `%c:name` (e.g. `%i:petId`):
1103
1106
1104
1107
| Format Char | Type |
1105
1108
| ----------- | ---- |
@@ -1112,6 +1115,8 @@ The format string supports the following format chars:
1112
1115
|`%O`|`Guid` (including short GUIDs*) |
1113
1116
|`%u`|`uint64` (formatted as a short ID*) |
1114
1117
1118
+
**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`.
1119
+
1115
1120
*) Please note that the `%O` and `%u` format characters also support URL friendly short GUIDs and IDs.
1116
1121
1117
1122
The `%O` format character supports GUIDs in the format of:
0 commit comments