Can a route start with a variable?

This DTO

[Route("/{Module}/{Name}")] public class ViewEntityList { public string Module { get; set; } public string Name { get; set; } } 

results in an error when starting the application with

RestPath '/ {Module} / {Name}' for type 'ViewEntityList' is not valid

I could change the route to start with a literal (for example, /Entity/{Module}/{Name} ), but this is not what I want; also, my urls are starting to look overly long and not like REST.

Is it possible to start a route with a variable? If not, is there another way to map any two-part route to a specific DTO?

+4
source share
1 answer

I always do the following:

  //Configure User Defined REST Paths Routes .Add<DTO1>("/service/function/{argument}") .Add<DTO2>("/service/commonsegment/{Function*}") 

the mapping for DT1 is the "base" mapping, one URL corresponds to the DTO.

in DTO2 you will need a key called "Function", which will give you the name of the first "not common" segment of the URL, any other segments specified in the URL will be mapped to your DTO2, if possible (if it has a property compliance). Thus, you open new functions / arguments, without changing the web server itself, but only the implementation of support (which can / should be located on an external dll).

Hope this helps.

0
source

Source: https://habr.com/ru/post/1447564/


All Articles