user1588242
user1588242

Reputation: 35

Calling a Post and Delete method in a Web api controller

I'm new to the this topic MVC4 and Web api. My question could be basic but do help me. I used (http://localhost:3668/api/values) and (http://localhost:3668/api/values/3) to call the methods get and get(int id) to get executed. But don't know how to call the Post and delete method in api controller thanks.

Upvotes: 0

Views: 1379

Answers (2)

Jordi
Jordi

Reputation: 2797

Post will be detected if you click on a form button. From C# code you can do something like that

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:3668/api/values/3");
request.Method = "DELETE";

Upvotes: 1

You cannot just punch the addresses into your favorite browser. A flexible solution for development and debugging is a command line tool like curl (http://curl.haxx.se/) which is capable of sending HTTP GET, POST, PUT, DELETE etc.

In order to consume the api from your application then it all depends on your client technology. If you are making a browser based application you can use xmlhttprequest to send GET, POST, PUT, DELETE requests. If you need server to server communication you can use System.Net.WebClient.

Upvotes: 0

Related Questions