Jc Balantakbo
Jc Balantakbo

Reputation: 115

When and how to use POST, PUT, and Delete method in Web API

I am new to Web API and the tutorial I was watching uses Fiddler to sniff and send request.

My question is how to use the post, put and delete methods without using fiddler and where are these usually used in the when creating in software development? Fiddler allows you to compose a request body how about the browser though?

I don't seem to understand why you are only able to use these on a sniffing tool. I understand that I am most probably speaking out of ignorance.

Upvotes: 0

Views: 1396

Answers (2)

EdSF
EdSF

Reputation: 12351

If you simply want to create requests using some tool, then you can use tools like Fiddler, Postman, curl, etc. - as you have stated, Fiddler can also be used to monitor as well as create requests.

If you want to go beyond that,

  • you have HttpClient, WebClient to build requests on your own, and for testing.
  • If you want to get "full control" then look into HttpWebRequest.
  • VS debugging tools will allow you to inspect the full flow - from request to response - using things like breakpoints, watch, etc.

See previous/other answers if you want to build/create requests client-side (Javascript / XMLHttpRequest)

Hth.

Upvotes: 1

lpd
lpd

Reputation: 2337

(This answer is not specific to ASP.NET)

To avoid any confusion, I'm assuming you understand this much about RESTful webservices:

  • If you are creating a new entity, use POST.
  • If you are reading an entity, use GET.
  • If you are updating an entity, use PUT.
  • If you are deleting an entity, use DELETE.

As you noticed, only the GET and POST methods can be used in plain web forms. AJAX, however, supports using any HTTP method. Therefore, to use the PUT and DELETE methods, send your data to the server using JavaScript methods such as XMLHttpRequest, the newer Fetch API or a convenient wrapper like jQuery's $.ajax. (There are many tutorials for whichever you pick.) For example, if you have a form of updated values, replace your input button with a button element that has a JavaScript click event handler. The same principle applies to a delete link, swap the href for a click event handler that makes an AJAX request to your server.

Upvotes: 1

Related Questions