.ToUrl with PUT verb in RouteAttribute

I have the following poco

[Route("/api/whatever", "PUT")]
public class Check : IUrlFilter
    public string Token { get; set; }

    public string ToUrl(string absoluteUrl)
        return Token.IsNullOrEmpty() ? absoluteUrl : absoluteUrl.AddQueryParam("token", Token);

Is it expected behaviour that new Check().ToUrl() throws the following exception but new Check().ToPutUrl() works correctly?

None of the given rest routes matches ‘Check’ request:
/api/whatever: Allowed HTTP methods ‘PUT’ does not support the specified ‘GET’ method.

[EDIT] I just saw the default verb on ToUrl() is set to “GET” so I guess that is the reason for the error, is there a way to generate the route by relying on the RouteAttribute rather than the passing the verb?

That’s not possible, a Service can have many routes definitions with different verbs and variables/weights, you need to tell it which verb you want at the call-site, reverse routing then picks the most appropriate route based on the verb and populated DTO.

Makes sense, thanks.

How can I exclude a request type from being returned by the ‘Add ServiceStack Reference’ DTO generation?

I am filtering these using the metadata in a plugin as below using the fact that SS internal types have an ExcludeAttrribute but adding that attribute to my request also isn’t excluding it from generation

host.Metadata.RequestTypes.Where(x => !x.HasAttribute<ExcludeAttribute>())

I want to create a service + request which is internal to a plugin’s implementation.

Can you open a new question/thread for this please? it’s not covered by the original question and makes it difficult for others to find the answers to.

Actually I’ve just found the answer when typing a new question (so therein lies the lesson!). Will apply this advice for the future.


Right, this is also why it should have its own question/thread, so it can be found.

BTW I’ve also expanded the wiki to document the different options for excluding services.