REST URI命名约定的联结表

假设我有三张桌子

product (id, name) customer (id, name) product_customer (product_id, customer_id) 

我已经为productcustomer遵守了REST服务(URI)

 GET /products => get all products GET /products/:id => get details on a specific product POST /products => add a product PUT /products/:id => update a product DELETE /products/:id => delete a product Same as above for /customers 

现在连接表product_customer需要一个URI和REST约定检索logging按照以下需要

a) /product_customer (将通过customer_id参数来获取客户购买的所有产品)

b) /product_customer (将通过product_id参数来获取所有购买此产品的客户)

我需要一个REST的uri约定连接表能够检索logging的两个PARAMS,有没有任何标准的惯例呢?

编辑示例JSON

 { "products": [ { "id": 1, "name": "product 1" } ], "customers": [ { "id": 1, "name": "john" }, { "id": 2, "name": "jane" }, ] } 

编辑2 – build议的URI基于评论

复数(与s)

GET /products – 列出所有产品

GET /products/1 – 产品ID为1的名称等详细信息(无客户)

单数

GET /product/1 – 一个产品的细节加上它的顾客

GET /product/1/customers只有产品的客户1

那么,如果你在你的模型中创build了多对多的关联,比如:

API /模型/ Product.js

 module.exports = { attributes: { id: { type: 'integer', primaryKey: true, autoIncrement: true, unique: true }, name:'string', // Add a reference to Customer model customers: { collection: 'customer', via: 'products' } } } 

API /模型/ Customer.js

 module.exports = { attributes: { id: { type: 'integer', primaryKey: true, autoIncrement: true, unique: true }, name:'string', // Add a reference to Product model products: { collection: 'product', via: 'customers' } } } 

之后,您将可以通过Blueprint API请求:

所有客户产品 ID为1:

 GET /product/1/customers 

所有产品客户 ID 5:

 GET /customer/5/products 

请注意,型号名称是产品和客户是单数 – 没有',他们的协会是产品和客户! 这我怎么样,你可以像你想要的名字。