asp.net - REST uri for POST and return(GET) -
sorry strange title. here situation.
i have table of products name , display order of each product. client can change display order of products. table generated using jquery.tmpl , data pulled using under wcf. products pulled db categoryid.
when user changes display order of product in grid product needs updated using post. once data has been updated server needs send updated json object update table.
question: how structure post uri scenario? here 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 uri updating resource correct updating single product category id. however, want return new set of products based on changes made post , not have make separate call.
not sure if 'right'. restafarians have me spooked!
thanks.
update started thinking bit more code above , realized there more going on here. reality of situation trying update specific product productid , return list of products categoryid. post , get. uri this?
[webinvoke( method = "post", uritemplate = "product/form/{productid}/products/{categoryid}")] [return: messageparameter(name = "products")] list<product> updateproduct(string productid, string categoryid);
with method 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 link daniel provided. although handling in 1 post call appears make sense, don't think conforms spirit of rest , using uri's resources. using post , call appears answer. daniel. comments good.
a post
or put
request update display order should not return anything, except status code indicates status of request. should issue separate get
request receive new list of top 15/25/50/etc products:
if new resource created, origin server must inform user agent via 201 (created) response. if existing resource modified, either 200 (ok) or 204 (no content) response codes should sent indicate successful completion of request. if resource not created or modified request-uri, appropriate error response should given reflects nature of problem.
from: section 9.6 of http 1.1 specification
you may interested in checking out http spec (sections 9.5 , 9.6) , following stack overflow post:
that said, can think of 2 ways update display order of products:
send move-up or move-down request particular product_id. request can invoked whenever up/down button clicked.
send complete order_rank list whole category.
i believe latter more practical, may want expose both operations. first approach post
verb seems appropriate, second 1 use put
.
for first approach, imagine uris following:
post /products/{productid}/move-up post /products/{productid}/move-down
the above suggests we're creating "move-up" or "move-down" command. verb post
means "create" , noun (the action) "move-up" or "move-down" command, acts on particular product_id.
for second approach, see uri following:
put /categories/{categoryid}/order-rank
to can pass json/xml/etc representation each product_id order_rank number. verb put
means "update" , noun "order-rank" particular category_id.
Comments
Post a Comment