admin管理员组文章数量:1124161
Have an existing flat table with just 2 columns, with one columns data repeating itself. Example Below (sample data for demonstration purposes)
Table: OPEC_MEMBER_COUNTRY (represents countries that belong under OPEC)
Data:
opec_id | member_country |
---|---|
OPEC | USA |
OPEC | Oman |
OPEC | Canada |
OPEC | Mexico |
Have an existing flat table with just 2 columns, with one columns data repeating itself. Example Below (sample data for demonstration purposes)
Table: OPEC_MEMBER_COUNTRY (represents countries that belong under OPEC)
Data:
opec_id | member_country |
---|---|
OPEC | USA |
OPEC | Oman |
OPEC | Canada |
OPEC | Mexico |
Need to write a REST API to get[all countries of OPEC]/add/delete member countries. Considering different design options for API model/Object model (and best "resources" && URI) that gives clarity for users (to support operations around member countries).
Different options that could come up with
- URI - /opec/member_countries (with "Country" as API model class with single String name property)
- URI - /opec-member-countries (with entity itself used as model class - unclear on id relevant)
- URI - /org/OPEC/member-countries
Looking for advice/suggestions for modelling/resource identifications (although aware that REST architectural principles are completely independent of the technology that is used to persist information).
Share Improve this question edited 23 hours ago nik0x1 1,2322 gold badges7 silver badges25 bronze badges asked yesterday Arpit SArpit S 2953 silver badges10 bronze badges 1- Hello Arpit. What is opec_id? Why is it the same for all countries? – nik0x1 Commented yesterday
2 Answers
Reset to default 0Firstly, your database should be refined further. It doesn't make sense to have a column with just one data in it. either your DB holds both data (e.g. OPEC & Non-OPEC) and the DB table_name is good enough to asses that list has only OPEC Countries in it.
For your REST API, the most logical uri path would be /opec/member_countries for OPEC based
If you planning to make it extensible, then /org/{OPEC}/member-countries would be a better uri.
When designing an API, it is better to focus on the convenience and needs of users, rather than on the internal structure of data storage.
If you have or plan to have other organizations in your system, then I would choose the following option:
Getting all members of the organization:
GET /orgs/{org_id}/members
Adding a new member:
POST /orgs/{org_id}/members
The list of members to add is passed in the request body.
Removing an organization member:
DELETE /orgs/{org_id}/members/{country_code}
版权声明:本文标题:rest - API ModelObject model (identifying resources) for an non-normalized flat table entity - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736618167a1945516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论