I am new in web api and I am not also a very advanced developer. I've seen an article that shows how we can use multiple http verbs for a single action.
So I like to know that the approach is good. Otherwise then, what can be worse when someone uses multiple http verbs for a single action?
Code taken from this area https://www.codeproject.com/Articles/1005485/RESTful-Day-sharp-Security-in-Web-APIs-Basic#_Toc423441907
[GET("allproducts")]
[GET("all")]
public HttpResponseMessage Get()
{ }
[GET("productid/{id?}")]
[GET("particularproduct/{id?}")]
[GET("myproduct/{id:range(1, 3)}")]
public HttpResponseMessage Get(int id)
{ }
[POST("Create")]
[POST("Register")]
public int Post([FromBody] ProductEntity productEntity)
{ }
[PUT("Update/productid/{id}")]
[PUT("Modify/productid/{id}")]
public bool Put(int id, [FromBody] ProductEntity productEntity)
{ }
// DELETE api/product/5
[DELETE("remove/productid/{id}")]
[DELETE("clear/productid/{id}")]
[PUT("delete/productid/{id}")]
public bool Delete(int id)
{ }
1) In what kind of scenario people use multiple http verbs for a single action because they create multiple routes for a single action that can confuse people ....... should approach below is good or not ?
[GET("productid/{id?}")]
[GET("particularproduct/{id?}")]
[GET("myproduct/{id:range(1, 3)}")]
public HttpResponseMessage Get(int id)
{}
2)PUT and DELETE is different verbs. how one can use different verbs for single action....is it right approach.
[DELETE("remove/productid/{id}")]
[DELETE("clear/productid/{id}")]
[PUT("delete/productid/{id}")]
public bool Delete(int id)
{
if (id > 0)
return _productServices.DeleteProduct(id);
return false;
}
please clarify the pros and corns of the above code and approach in details. thanks