Felipe Windmoller
Felipe Windmoller

Reputation: 1753

What is the best body for POST when the Path Parameters already have some of the resource information

I have one resource accessible through:

users/{userName}/shoppings/{shoppingName}/products/{productName}

This is the Product table that will store the information:

When the front end make a POST request to users/{userName}/shoppings/{shoppingName}/products to create a Product, what should I pass on the body?

Should I pass only:

productName;
quantity

Or should I pass the complete object?:

userName;
shoppingName;
productName;
quantity.

In the back end, as I'm capturing the userName and shoppingName from the Path Parameters, I thought it would make more sense in the body to just send the productName and quantity, but I'm not sure.

Thanks in advance!

Upvotes: 0

Views: 29

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57249

what should I pass on the body?

Probably everything in the body; the argument being that style allows you to easily change the URI later.

Consider forms on the web - data in the input controls is copied according to HTML's form processing rules, and then the form metadata is used to determine the target URI of the request.

That allows us to easily change the target URI when we generate the HTML. For instance, we might want to take advantage of cache invalidation or introduce a URL shortener.

That said: shrug. The entire HTTP request is all going to the same place, and the server has a lot of discretion in how it interprets a POST request.

Upvotes: 1

Related Questions