dimanche 5 février 2023

F# ASP.NET Core Minimal Web API - Why does the generated endpoint ignore parameter names when not supplied a lambda?

I created a .NET core web API from the standard F# template and added these lines:

let add x y = x + y

app.MapGet("addUgly", new Func<_,_,_>(add))

app.MapGet("addPretty", new Func<_,_,_>(fun x y -> add x y))

When I access the addPretty endpoint, I can supply parameters with the desired names: https://localhost:7129/addPretty?x=1&y=2

However, in order to access the addUgly endpoint, I must supply these parameters: https://localhost:7129/addUgly?delegateArg0=3&delegateArg1=4

Is there a way to have the generated endpoint use the desired parameter names without using a lambda? (or other constructs that involve unnecessary boilerplate, like creating a controller)?

I checked whether add and (fun x y -> add x y) had differently structured type definitions, but they both have Invoke methods with parameters named x and y, so I don't know why those names get lost in one case but not the other.





Aucun commentaire:

Enregistrer un commentaire