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

  1. URI - /opec/member_countries (with "Country" as API model class with single String name property)
  2. URI - /opec-member-countries (with entity itself used as model class - unclear on id relevant)
  3. 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
Add a comment  | 

2 Answers 2

Reset to default 0

Firstly, 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}

本文标签: restAPI ModelObject model (identifying resources) for an nonnormalized flat table entityStack Overflow