Skip to content

Routes with named parameters are not matched #704

@acatuttle

Description

@acatuttle

Describe the bug

Calls to a route with a named parameter, e.g. "/pet/%i:petId" are not matched.

Expected behavior

Calls should be matched as described in the named parameter example in the documentation for routef.

To Reproduce

  1. Set up a minimal web app:
// GiraffeApp.fsproj
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Giraffe" Version="7.0.2" />
  </ItemGroup>
  
</Project>
// Program.fs
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Giraffe

let webApp =
    choose [
        // Named parameter example:
        routef "/pet/%i:petId" (fun (petId: int) -> text (sprintf "PetId: %i" petId))

        // If none of the routes matched then return a 404
        RequestErrors.NOT_FOUND "Not Found"
    ]

let configureApp (app : IApplicationBuilder) =
    // Add Giraffe to the ASP.NET Core pipeline
    app.UseGiraffe webApp

let configureServices (services : IServiceCollection) =
    // Add Giraffe dependencies
    services.AddGiraffe() |> ignore

[<EntryPoint>]
let main _ =
    Host.CreateDefaultBuilder()
        .ConfigureWebHostDefaults(
            fun webHostBuilder ->
                webHostBuilder
                    .Configure(configureApp)
                    .ConfigureServices(configureServices)
                    |> ignore)
        .Build()
        .Run()
    0
  1. Start the app and make a call to the endpoint:
    PowerShell 7.5.4
    PS C:\> curl -X GET "https://localhost:7162/pet/1" -k
    "Not Found"

Exceptions

None.

Environment:

  • OS: Windows 11
  • .NET version: 9.0.308

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugReproducible bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions