开发者

If I want to get a list of all products that a certain customer has purchased, how would I express this relationship using RESTful conventions?

开发者 https://www.devze.com 2023-03-27 00:18 出处:网络
So if I wanted to get a list of all products, I\'d use an HTTP GET request on /products, and if I wanted to get a specific product, I\'d us开发者_高级运维e an HTTP GET request on /products/:id, but wh

So if I wanted to get a list of all products, I'd use an HTTP GET request on /products, and if I wanted to get a specific product, I'd us开发者_高级运维e an HTTP GET request on /products/:id, but what is the convention if I want to get a list of all of the products that a certain customer has purchased? Using a nested resource in this case wouldn't make sense.


You can go a couple of ways here, but the noun here is really a "purchase"

So /purchases could be your list of purchases.

/purchases/1 and /purchases/2 are the first and second purchases you created.

"transactions" would work just as well here.

0

精彩评论

暂无评论...
验证码 换一张
取 消