user2727195
user2727195

Reputation: 7330

some more help for naming conventions plural vs singular

There are answers out there but my question is different as I'm trying to find out a uri when I've detail on a product or when I've to return detail on a product plus it's customers. I need a standard solution for following 4 api calls. I need a standard naming convention for this particular situation, please fix them from the following.

Plural (with s)

GET /products - List all products

GET /products/1 - Detail of the product ONLY (no customers)

Singular

GET /product/1 - Detail of a product plus it's customers

GET /product/1/customers ONLY customers of product 1

From the above I'm trying to find a solution for these two.

GET /products/1 - Detail of the product ONLY (no customers)

GET /product/1 - Detail of a product plus it's customers

Upvotes: 0

Views: 2203

Answers (1)

user1907906
user1907906

Reputation:

No, don't use differen URLs to differentiate between the product with and without customers. Use content negotioation.

To get a product with embedded customers, use one Accept header:

GET /products/1
Accept: application/vnd.com.example.rest.customer.long+json

To get a product without customers, use a different Accept header.

GET /products/1
Accept: application/vnd.com.example.rest.customer.short+json

But always use the same URL since you are requeting the same resource. To request diferent representations of this URL, use content negotiation.

Upvotes: 1

Related Questions