I want to have ServiceStack endpoints such as the following...
[RestService("/items/recent")]
[RestService("/items/recent/{Page}")]
[RestService("/items/popular")]
[RestService("/items/popular/{Page}")]
Since both would return a List<Item>
, I'd love to be able to have both of these in the same RestServiceBase
for easier code management. Is this possible? If so, how can I differentiate the request when it comes in to find whether it was a "recent" or "popular" request so that I can handle it appropriately?
Yes you can have multiple REST-ful paths pointing to the same web service.
If you want to leave the paths as-is you can inspect the Request Path used to invoke the service via the HttpRequest, i.e:
The way you work out what type of request it is, is by looking at the populated Request DTO - but to distinguish between /recent/ and /popular/ you should store it in another Request DTO property and then inspect its values i.e.
This is also similar to this StackOverflow question: Need help on servicestack implementation