REST uri for POST and return (GET)

Sorry for the weird name. Here is my situation.

I have a product table with the name and display order of each product. Customer can change the display order of products. The table is created using jQuery.tmpl, and the data is retrieved using GET under WCF. Products extracted from db are CategoryID.

When the user changes the display order of the product in the grid, the product must be updated using POST. After updating the data, the server should send back the updated json object to update the table.

QUESTION: How do I structure my POST uri for this scenario? Here is what I have.

 [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);

, uri , . , , POST, GET.

, "". !

.

UPDATE , . , ProductID, THEN CategoryID. POST GET. URI?

[WebInvoke(
Method = "POST",
UriTemplate = "product/form/{productId}/products/{categoryId}")]
[return: MessageParameter(Name = "products")]
List<Product> UpdateProduct(string productId, string categoryId);

?

public static List<Product> UpdateProduct(string productId, string categoryId)
{
ProductManager.UpdateProduct(int.Parse(productId));
return ProductManager.GetProducts(int.Parse(categoryId));
}

UPDATE2

. POST , , REST Uri . POST, GET - . . .

+3
1

A POST PUT , , . GET 15/25/50/ ..:

,     201 (). ,     200 (OK), 204 ( )     .     Request-URI,     ,    .

: 9.6 HTTP 1.1

HTTP Spec ( 9.5 9.6) :


, :

  • product_id. , "/".

  • order_rank .

, , . POST , PUT.

, URI :

POST /products/{productId}/move-up
POST /products/{productId}/move-down

, "move-up" "move-down". POST "create", () - "move-up" "move-down", product_id.

URI :

PUT /categories/{categoryId}/order-rank

JSON/XML/etc product_id order_rank. PUT "", - "-" _.

+1

Source: https://habr.com/ru/post/1768473/


All Articles