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
open Falco
open Falco.Routing
open Falco.HostBuilder
webHost [||] {
endpoints [
get "/hello/{name:alpha}" (fun ctx ->
let route = Request.getRoute ctx
let name = route.GetString "name" "" // <- This Doesn't compile for me
let message = sprintf "Hello %s" name
Response.ofPlainText message ctx)
]
}
However this is completely fine:
webHost [||] {
endpoints [
get "/hello/{name:alpha}" (fun ctx ->
let route = Request.getRoute ctx
let name = route.GetString ("name", "") // Change to tupled parameters made here
let message = sprintf "Hello %s" name
Response.ofPlainText message ctx)
]
}
open Falco
// Assuming a route pattern of /{Name}
let manualRouteHandler : HttpHandler = fun ctx ->
let r = Request.getRoute ctx
let name = r.GetString "Name"
Response.ofPlainText name ctx
let mapRouteHandler : HttpHandler =
Request.mapRoute (fun r ->
r.GetString "Name")
Response.ofPlainText
Which would translate our first example to something like this:
webHost [||] {
endpoints [
get "/hello/{name:alpha}" (fun ctx ->
let route = Request.getRoute ctx
let name = route.GetString "name"
let message = sprintf "Hello %s" name
Response.ofPlainText message ctx)
]
}
That would be one of my suggestion the other is using a working tupled example in a more descriptive way:
webHost [||] {
endpoints [
get "/hello/{name:alpha}" (fun ctx ->
let route = Request.getRoute ctx
let name = route.GetString ("name", "FalcoEnthusiast") // Could be "defaultValue", "fallbackValue"
let message = sprintf "Hello %s" name
Response.ofPlainText message ctx)
]
}
But my question is will it ever be an empty string here? Maybe the fallback value is never needed in this example?
I would be very happy to make a PR for that, but it is also a trivial change so might be an overkill.
Have a great New Year Pim and everyone! :)
The text was updated successfully, but these errors were encountered:
Hello, I've noticed a small issue here:
https://github.com/pimbrouwers/Falco/blob/master/doc/routing.md
However this is completely fine:
The route binding example from here: https://www.falcoframework.com/docs/request.html#route-binding
Is completely fine and uses a simplified version, like this:
Which would translate our first example to something like this:
That would be one of my suggestion the other is using a working tupled example in a more descriptive way:
But my question is will it ever be an empty string here? Maybe the fallback value is never needed in this example?
I would be very happy to make a PR for that, but it is also a trivial change so might be an overkill.
Have a great New Year Pim and everyone! :)
The text was updated successfully, but these errors were encountered: