ServiceStack Rest - Complex uri hierarchies

与世无争的帅哥 提交于 2019-12-24 07:55:18

问题


I'm creating a rest webservice using the c# framework 'servicestack' (http://www.servicestack.net/) and I'm having issues trying to figure out how to support more complex rest hierarchies

And I'm configuring various routes and it works perfectly

Routes
    .Add<MerchantDto>("/merchants")
    .Add<MerchantDto>("/merchants/{id}")
    .Add<MerchantDto>("/merchantGroups/{merchantGroupId}/merchants")
    .Add<MerchantDto>("/merchantGroups/{merchantGroupId}/merchants/{id}")

    .Add<StoreDto>("/stores")
    .Add<StoreDto>("/stores/{id}")
    .Add<StoreDto>("/merchants/{merchantId}/stores")
    .Add<StoreDto>("/merchants/{merchantId}/stores/{id}");

This all works fine. This problem is doing this....

    .Add<StoreDto>("/merchantGroups/{merchantGroupId}/merchants/{merchantId}/stores/{id}

The problem here is that the StoreDto object only contains a MerchantId, it does not contain a MerchantGroupId so this wouldn't work.

One solution would be to add the MerchantGroupId to the DTO but the problem is that I am sharing the DTO with some other WCF services and it might be confusing if I were have a MerchantGroupId property in the StoreDto which is never populated during a retrieval operation.

Plus I see this as cropping up at different places so I was hoping there was a better way to do it.

Any suggestions?


回答1:


Like @myth says I am just making things complicated by trying to generate MVC-like url paths.

I am sticking to using the uri paths as is.



来源:https://stackoverflow.com/questions/12510017/servicestack-rest-complex-uri-hierarchies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!