rest - API ModelObject model (identifying resources) for an non-normalized flat table entity - Stack Overflow

admin2025-04-28  2

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 Jan 10 at 18:05 nik0x1 1,5582 gold badges8 silver badges26 bronze badges asked Jan 9 at 18:19 Arpit SArpit S 2913 silver badges12 bronze badges 1
  • Hello Arpit. What is opec_id? Why is it the same for all countries? – nik0x1 Commented Jan 10 at 9:55
Add a comment  | 

2 Answers 2

Reset to default 1

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}

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.

转载请注明原文地址:http://anycun.com/QandA/1745781090a91204.html