Suggested Videos
Part 1 - What is ASP.NET Web API
Part 2 - Creating a Web API Project
In this video we will discuss HTTP PUT, POST and DELETE verbs. This is continuation to Part 2. Please watch Part 2 from ASP.NET Web API tutorial before proceeding.
When we talk about a database table row, these are the following 4 actions that we can perform on the row
C - Create a row
R - Read a row
U - Update a row
D - Delete a row
In the context of an ASP.NET Web API resource these 4 actions correspond to GET, POST, PUT and DELETE as shown in the table below
Let us now understand some terms and concepts related to HTTP request and response system.
Request Verbs : These HTTP verbs (GET, POST, PUT & DELETE) describe what should be done with the resource. For example do you want to create, read, update or delete an entity. GET, PUT, POST and DELETE http verbs are the most commonly used one's. For the complete list of the HTTP verbs, please check http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Request Header : When a client sends request to the server, the request contains a header and a body. The request header contains additional information such as what type of response is required. For example, do you want the response to be in XML or JSON.
Request Body : Request Body contains the data to send to the server. For example, a POST request contains the data for the new item that you want to create. The data format may be in XML or JSON.
Response Body : The Response Body contains the data sent as response from the server. For example, if the request is for a specific product, the response body includes product details either in XML or JSON format.
Response Status codes : These are the HTTP status codes, that give the client details on the status of the request. Some of the common status codes are 200/OK, 404/Not Found, 204/No Content. For the complete list of HTTP status codes and what they mean, please visit http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
We will use a tool called fiddler to perform POST, PUT & DELETE actions. You can download fiddler from the following link
https://www.telerik.com/download/fiddler
Modify the ValuesController as shown below, so that it can support POST, PUT and DELETE actions.
Post(), Put() and Delete() methods in our ValuesController are returning void. That is the reason we are getting status code 204 No Content. An action that returns void will send status code 204 No Content. With ASP.NET Web API, we can control what status codes these methods return. We will discuss how to do that in a later video.
Part 1 - What is ASP.NET Web API
Part 2 - Creating a Web API Project
In this video we will discuss HTTP PUT, POST and DELETE verbs. This is continuation to Part 2. Please watch Part 2 from ASP.NET Web API tutorial before proceeding.
When we talk about a database table row, these are the following 4 actions that we can perform on the row
C - Create a row
R - Read a row
U - Update a row
D - Delete a row
In the context of an ASP.NET Web API resource these 4 actions correspond to GET, POST, PUT and DELETE as shown in the table below
CRUD | HTTP Verb |
---|---|
Create | POST |
Read | GET |
Update | PUT |
Delete | DELETE |
Let us now understand some terms and concepts related to HTTP request and response system.
Request Verbs : These HTTP verbs (GET, POST, PUT & DELETE) describe what should be done with the resource. For example do you want to create, read, update or delete an entity. GET, PUT, POST and DELETE http verbs are the most commonly used one's. For the complete list of the HTTP verbs, please check http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Request Header : When a client sends request to the server, the request contains a header and a body. The request header contains additional information such as what type of response is required. For example, do you want the response to be in XML or JSON.
Request Body : Request Body contains the data to send to the server. For example, a POST request contains the data for the new item that you want to create. The data format may be in XML or JSON.
Response Body : The Response Body contains the data sent as response from the server. For example, if the request is for a specific product, the response body includes product details either in XML or JSON format.
Response Status codes : These are the HTTP status codes, that give the client details on the status of the request. Some of the common status codes are 200/OK, 404/Not Found, 204/No Content. For the complete list of HTTP status codes and what they mean, please visit http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
We will use a tool called fiddler to perform POST, PUT & DELETE actions. You can download fiddler from the following link
https://www.telerik.com/download/fiddler
Modify the ValuesController as shown below, so that it can support POST, PUT and DELETE actions.
public class ValuesController : ApiController
{
static List<string> strings = new List<string>()
{
"value0", "value1", "value2"
};
// GET api/values
public IEnumerable<string> Get()
{
return strings;
}
// GET api/values/5
public string Get(int id)
{
return strings[id];
}
// POST api/values
public void Post([FromBody]string value)
{
strings.Add(value);
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
strings[id] = value;
}
// DELETE
api/values/5
public void Delete(int id)
{
strings.RemoveAt(id);
}
}
Post(), Put() and Delete() methods in our ValuesController are returning void. That is the reason we are getting status code 204 No Content. An action that returns void will send status code 204 No Content. With ASP.NET Web API, we can control what status codes these methods return. We will discuss how to do that in a later video.
Thank you venkat sir. Good Explanation.
ReplyDeletethank you so much sir :D
ReplyDeleteHi Sir, Can you please help in creating a SQL script to delete old files on shared drives. It has to be done via SQL.
ReplyDeleteWhats the need of PUT and Delete as we also do this using POST method?
ReplyDeleteCan you please explain the difference between put and post?
Put is Used To Add data row in table and post is used to update that data rowl
ReplyDelete"Postman" plugin is very useful in Chrome to test the webapi.
ReplyDeleteHello Sir,
ReplyDeleteVery Nice Explanation. I wanted to know one thing that if there are more than one browser opened and I want receive only on browser's requests, how to set this in the fiddler??
Hi,
ReplyDeleteI need to add a new Name without using fiddler. by using json file we can do it. But how to use that.
Dear Sir,
ReplyDeleteAs we learnt many videos of ASP.Net and I would like see videos about PYTHON and Machine Learning as well as AI, Is it Possible? if Yes, Plz share and Upload that Videos as soon as Possible...