1

I am creating a REST service that will expose for example customers and suppliers and each have associated contacts

I want to be able to route to:

  • /contacts
  • /contacts/{id}
  • /suppliers/{supplierId}/contacts
  • /suppliers/{supplierId}/contacts/{id}
  • /customers/{customerId}/contacts
  • /customers/{customerId}/contacts/{id}

I know I can easily add:

[Route("/contacts", "GET")]
[Route("/contacts/{id}", "GET")]
[Route("/{Entity}/{EntityId}/contacts", "GET")]
[Route("/{Entity}/{EntityId}/contacts/{id}", "GET")]
Class ContactsRequest :IReturn<ContactsResponse>{
...
}

But I want to be able to use my Contacts Service where it could be at the end of a "deeper" route for example:

  • /sales/leads/{leadId}/referers/customers/{customerId}/contacts
  • /sales/leads/{leadId}/referers/customers/{customerId}/contacts/{id}

I am planing on using this API with restangular, I want to be able to drill down the api from anywhere in the app. Any Suggestions?

4

1 回答 1

1

阅读后:http: //info.apigee.com/Portals/62317/docs/web%20api.pdf

现在,关系可能很复杂。主人与兽医有关系,与狗有关系,与食物有关系,等等。经常看到人们将这些链接在一起,使 URL 达到 5 或 6 级深度。请记住,一旦您拥有一个级别的主键,您通常不需要包含上述级别,因为您已经获得了您的特定对象。换句话说,你不应该需要太多比我们上面的 /resource/identifier/resource 更深的 URL 的情况。

基本上我所追求的设计是不好的做法......

于 2013-11-11T08:23:34.690 回答