Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use predefined routes in ServiceStack with URI instead of query string?

Is it possible (if yes, how) in ServiceStack to use predefined routes with parameters in the URI? I can do one or the other but combining both does not seem to work:

[Route("/hello/{Name}")]

// ok
1. /hello/myname
2. /json/reply/hello
3. /json/reply/hello?Name=myname

// not ok
4. /json/reply/hello/myname
"The operation 'myname' does not exist for this service"

Tried these but none worked:

[Route("/*/hello/{Name}")]
[Route("/{*}/hello/{Name}")]

In particular, why does 3 work, but not 4? Thanks!

like image 838
evilmandarine Avatar asked Feb 03 '26 06:02

evilmandarine


1 Answers

No, ServiceStack's pre-defined routes are not customizable and follow the explicit format:

/{format}/[reply|oneway]/{servicename}

i.e. you can define your own Custom routes, but you can't change the pre-defined routes which maintains its pre-defined behavior.

To send parameters on the URL you need to use the queryString, e.g:

 /json/reply/Hello?name=myname

Otherwise you can send parameters using other methods that ServiceStack supports, e.g. serialized Request Body, FormData, HTTP Headers, etc.

like image 126
mythz Avatar answered Feb 05 '26 22:02

mythz