HTTP Verbs In MVC 5

Introduction

 
In this article, I will explain the concept of HTTP verbs in MVC 5. I will also explain the various types of HTTP verbs in MVC 5 and how it works in the project.
 

Objective

 
In this article, we will discuss the following terms.
  • What is HTTP
  • What are HTTP verbs?
  • when can we use HTTP verbs?
  • How to use HTTP Verbs.
  • Where to use HTTP Verbs.
  • And, a lot of things about HTTP Verbs. 

What is HTTP?

  • HTTP stands for hypertext transfer protocol.
  • This protocol works while working with a client-server application.
  • This protocol provides communication between the client and the server. 
Http Verbs in MVC 5
 

HTTP Verbs

 
HTTP provides methods (verbs) for the actions performed on a response. HTTP verbs are used on an action method. HTTP provides the following main verbs.
  • Get
  • Post
  • Put
  • Delete

HTTP Get

 
This verb is used to get existing data from the database. In HttpGet, data travels in the URL only. To use the HttpGet method, we use HttpGet attribute on the Action method. It is also the default HTTP verb.
 
Example
 
domain.com/student/GetStudent/1
domain.com/student/GetStudent?studentid=1
  1. [HttpGet]  
  2. public object GetStudent(int studentid)  
  3. {  
  4.    // code here  
  5. }  

HTTP Post

 
This verb is used while we have to create a new resource in the database. In HttpPost, data travels in the URL and body. To use HttpPost method, we use HttpPost attribute on the Action method.
 
Example
 
domain/student/Studentsave
Body - Json body 
  1. [HttpPost]  
  2. public object Studentsave(studentclass obj)  
  3. {  
  4. }  

HTTP Put

 
This verb is used while we have to update an existing resource in the database. In HttpPut, the data travels in the URL and body. To use HttpPut method, we use HttpPut attribute on the Action method.
 
Example
 
domain.com/student/studentupdate/1
Body- Json body 
  1. [HttpPut]  
  2. public object Studentupdate(int studentid ,Studentclass objVM)  
  3. {  
  4. }  

HTTP Delete

 
This verb is used while we have to delete the existing resources in the database. In HttpDelete, data travels in the URL and body. To use HttpDelete, we use HttpDelete attribute on the Action method. 
 
Example
 
domain.com/student/studentdelete/1
  1. [HttpDelete]    
  2. public object Studentupdate(int studentid)    
  3. {    
  4. }   

Summary 

 
In this article, I have discussed HTTP Verbs. I hope you will find them useful. 


Similar Articles