How to reference an endpoint in another one?

送分小仙女□ 提交于 2020-01-06 01:44:48

问题


In Eve demo, a people collection as endpoint is set up, however there is no id created for it. So if I want to create a endpoint a level up to reference 'people', it seems not easy.

What I want to do for example:

The structure: company->dept(people)->person

So if I visit www.example.com/company, I get a organized list of people, grouped with dept.

So far I can create person, create different dept(people) endpoints, but how to put all these in a company endpoint?

Thanks


回答1:


You probably want to use Sub Resources endpoints. The documentation provides the following example:

invoices = {
    'url': 'people/<regex("[a-f0-9]{24}"):contact_id>/invoices'
     ...

Then you could send a GET like this:

people/51f63e0838345b6dcd7eabff/invoices

which would roughly translate to: give me all invoices by <contact_id>. Follow the link above for detailed explanation of how it works.

UPDATE after reading the comment

Since you can have different endpoints all targeting the same datasource, each one with its one filter, you could probably achieve something like that. Both engineers and sales endpoints would consume a persons datasource. One would only return engineers, the other would only return sales people. Then your departments endpoint could either be consuming a different datasource (departments) and have a data relation on persons, or consume the same persons resource with a filter on a department field. Have not tested that, but worth giving it a spin perhaps. See Advanced Datasource Patterns.



来源:https://stackoverflow.com/questions/28024555/how-to-reference-an-endpoint-in-another-one

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