Is there any way to get the Segment of a URI using its name?
For example if I have the template:
http://myapi.com/v1/players/{country}
How could I extract the value of {country}
once it has been matched using UriTemplateMatch
?
I have read the docs for the class and currently use this approach
string country = requestedUri.Segments[3];
This method is fine for static URI's, but as soon as paths change it can be a lot of hassle to go back and make changes.
You can retrieve the bound variables using the BoundVariables
property of the UriTemplateMatch
You have a good example here
... so basically if we have
UriTemplateMatch results
after matching you can simply call
results.BoundVariables["country"];
to get what you are looking for. Unless I am missing the problem here, and for some reason you don't want to keep the UriTemplateMatch object.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments