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
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.
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
- [HttpGet]
- public object GetStudent(int studentid)
- {
-
- }
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
- [HttpPost]
- public object Studentsave(studentclass obj)
- {
- }
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
- [HttpPut]
- public object Studentupdate(int studentid ,Studentclass objVM)
- {
- }
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
- [HttpDelete]
- public object Studentupdate(int studentid)
- {
- }
Summary
In this article, I have discussed HTTP Verbs. I hope you will find them useful.