Sorry for the strange title. Here is my situation.
I have a table of products with the name and display order of each product. The client can change the display order of the products. The table is generated using jQuery.tmpl and the data is pulled using GET under WCF. The products pulled from the db are by CategoryID.
When the user changes the display order of a product in the grid the product needs to be updated using POST. Once the data has been updated the server needs to send back an updated json object to update the table.
QUESTION: How do I structure my POST uri for this scenario? Here is what I have now.
[OperationContract]
[WebInvoke(
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "product/form/{categoryId}")]
[return: MessageParameter(Name = "products")]
List<Product> UpdateProduct(string categoryId);
I believe my uri for updating the resource is correct as I am updating a single product by a category id. However, I want to return a new set of products based on the changes made by the POST and not have to make a separate GET call.
Not sure if this is 'right'. Those restafarians have me spooked!
Thanks.
UPDATE I started thinking a bit more about my code above and realized there is more going on here. The reality of my situation is that I am trying to update a specific product by ProductID and THEN return a list of products by CategoryID. Essentially a POST and a GET. So would my URI look like this?
[WebInvoke(
Method = "POST",
UriTemplate = "product/form/{productId}/products/{categoryId}")]
[return: MessageParameter(Name = "products")]
List<Product> UpdateProduct(string productId, string categoryId);
With my method like this?
public static List<Product> UpdateProduct(string productId, string categoryId)
{
ProductManager.UpdateProduct(int.Parse(productId));
return ProductManager.GetProducts(int.Parse(categoryId));
}
UPDATE2
This question has been addressed here with a link Daniel provided. Although handling everything in one POST call appears to make sense, I don't think it conforms to the spirit of REST and using Uri's as resources. Using a POST and then a GET call appears to be the answer. Thanks to Daniel. His comments are good.