tri_inn

tri_inn

  • NA
  • 1.2k
  • 235.3k

Web api related few questions

Jun 8 2017 10:43 AM
i have seen few code of your article. i am new in web api. so i just do not understand if i need to call these action then what will be their address or url?
please see your code and tell me what will be the address

sorry to ask few question. please answer that will guide me.

code taken from this area https://www.codeproject.com/Articles/1005485/RESTful-Day-sharp-Security-in-Web-APIs-Basic#_Toc423441907

  1. [GET("allproducts")]  
  2. [GET("all")]  
  3. public HttpResponseMessage Get()  
  4. {  
  5.   
  6. }  
  7.   
  8.   
  9. [GET("productid/{id?}")]  
  10. [GET("particularproduct/{id?}")]  
  11. [GET("myproduct/{id:range(1, 3)}")]  
  12. public HttpResponseMessage Get(int id)  
  13. {  
  14.   
  15. }  
  16.   
  17. [POST("Create")]  
  18. [POST("Register")]  
  19. public int Post([FromBody] ProductEntity productEntity)  
  20. {  
  21.   
  22. }  
  23.   
  24.   
  25. [PUT("Update/productid/{id}")]  
  26. [PUT("Modify/productid/{id}")]  
  27. public bool Put(int id, [FromBody] ProductEntity productEntity)  
  28. {  
  29.   
  30. }  
  31.   
  32. // DELETE api/product/5  
  33. [DELETE("remove/productid/{id}")]  
  34. [DELETE("clear/productid/{id}")]  
  35. [PUT("delete/productid/{id}")]  
  36. public bool Delete(int id)  
  37. {  
  38.   

1) what will be the address of this action public HttpResponseMessage Get()
will it be api/product ?

2) what will be the address of this action public HttpResponseMessage Get(int id)
will it be api/product/5 ?
  1. [GET("productid/{id?}")]  
  2. [GET("particularproduct/{id?}")]  
  3. [GET("myproduct/{id:range(1, 3)}")]  
  4. public HttpResponseMessage Get(int id)  
  5. {} 
why you decorate a single action with so many gets attribute ?
first 2 gets look same......is not it ?

3)
  1. [POST("Create")]  
  2. [POST("Register")]  
  3. public int Post([FromBody] ProductEntity productEntity)  
  4. {  
  5. return _productServices.CreateProduct(productEntity);  
  6.  
what will be the action url for Post action above ?

what two post is there with different keyword ?
what is the meaning of text inside post keyword like [POST("Create")] ?

4)
  1. [DELETE("remove/productid/{id}")]  
  2. [DELETE("clear/productid/{id}")]  
  3. [PUT("delete/productid/{id}")]  
  4. public bool Delete(int id)  
  5. {  
  6. if (id > 0)  
  7. return _productServices.DeleteProduct(id);  
  8. return false;  


why delete and post 2 verbs have been used for single action called Delete ?

please answer in details. thanks

Answers (1)