With the older version SomeService : RestServiceBase can match OnGet OnPost OnPut OnDelete actions with the coresponding incoming verbs.
With the newer version, say I have the following:
//-----------------------------------------
[Route("/todos/{id}","GET")] //display request
[Route("/todos/{id}", "POST")] //edit request
public class Todo : IReturn<TodoResponse> {
public long Id { get; set; }
public string Content { get; set; }
}
public class TodoService : Service {
public object Get(Todo request) { ... } // will GET verb know this Get() function?
public object Post(Todo request) { ... }// will POST verb know this Post() function?
}
The Action names “Get” “Post” are no longer marked “override”, how does SS match the correct verbs to hit Get() and Post() functions?
//————————————————————————–
Or Round 2, now I have a modification…
//-----------------------------------------
[Route("/todos/{id}","GET")] //display request
public class DisplayTodo : IReturn<TodoResponse> {
public long Id { get; set; }
}
[Route("/todos/{id}", "POST")] //edit request
public class EditTodo : IReturn<TodoResponse> {
public long Id { get; set; }
public string Content { get; set; }
}
public class TodoService : Service {
//different request DTOs this time ...
public object Get(DisplayTodo request) { ... } //again, same route "/todos/{id}"
public object Post(EditTodo request) { ... } //will SS get confused about the verbs?
}
Under the same route “/todos/{id}” how does SS distinguish verbs in the above cases?
Could you please sort me out with the 2 questions? Thank you!
This is the Smart Routing section taken from the New API wiki page:
Matching Rules
For the most part you won’t need to know about this as ServiceStack’s routing works as you would expect. Although this should still serve as a good reference to describe the resolution order of ServiceStack’s Routes:
These Rules only come into play when there are multiple routes that matches the pathInfo of an incoming request.
Lets see some examples of these rules in action using the routes defined in the new API Design test suite:
These are results for these HTTP Requests
And if there were multiple of the exact same routes declared like:
The Route on the Action that was declared first gets selected, i.e: