Reputation: 4633
I have 2 GET endpoints implemented via Azure Functions
/products/{productId}
: Gets me the product by id/products/status
: Get certain 'status' of the products collection.Doing GET calls always ends up in the 'Get by id' function.
How do I make these 2 explicit endpoints and not treat 'status' as an id value? I was under the impression that if a route matches the uri then it takes precedence.
Is related to this issue - https://github.com/MicrosoftDocs/azure-docs/issues/11755
Cannot use Route constraints for Guid ids.
/products/{productId:guid}
disambiguates the function calls but fails to bind the value to the parameter.
Upvotes: 4
Views: 2151
Reputation: 17790
fails to bind the value to the parameter
It's an issue tracked but not solved yet.
Route Constraints allow specifying datatypes for query string parameters on HttpTrigger route property. These constraints are only used to match the route. When using binding parameters datatype is converted to strings.
So if you use Guid productId
to accept the input parameter, you will meet the error Invalid cast from 'System.String' to 'System.Guid'
.
Workaround is to accept the guid as string, you can use Guid.Parse(productId)
if you need a Guid Object.
public static async Task<HttpResponseMessage> Run(..., Route = "product/{productId:guid}")]HttpRequestMessage req, string productId)
Upvotes: 2