asdf
asdf

Reputation: 667

Making restful calls to asp.net web api

I am currently following this tutorial to create a simple REST service using Web Api. Note this is my first time doing something like this and I am just trying to learn more.

http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations

I have followed all the instructions and have it successfully running on my localhost. I understand that in this tutorial the URI for all my GET requests look something like:

localhostapi/products/id

And I understand that, and how to perform simple GET requests in the URI and see it actually occuring using my developer tools in my browser.

Now my question is... How do I make POST/DELETE/PUT requests and actually see what they are doing? The guide wasn't too clear, do I pass in parameters into the URI? Does the URI change when I want anything but a GET request? This text here seems to explain it but I do not understand:

Upvotes: 3

Views: 780

Answers (3)

Vahid Hassani
Vahid Hassani

Reputation: 674

You can write unit tests, like

    [TestMethod]
    public void GetAllProducts_ShouldReturnAllProducts()
    {
        var testProducts = GetTestProducts();
        var controller = new SimpleProductController(testProducts);

        var result = controller.GetAllProducts() as List<Product>;
        Assert.AreEqual(testProducts.Count, result.Count);
    }

This link also This one may help.

more:

How to call ASP .NET MVC WebAPI 2 method properly

Sending C# object to webapi controller

Upvotes: 1

Toan Nguyen
Toan Nguyen

Reputation: 11581

It's quite easy to make POST, PUT, DELETE requests. You just need to install Fiddler at http://www.telerik.com/download/fiddler

Next, install and run it. Go to the Composer tab on the right hand side. Next, put your local host URL, and the request method, and other data like the screenshot belowenter image description here

Upvotes: 1

Geoff
Geoff

Reputation: 210

You can set a breakpoint on your controller methods that handle the post/delete/put.

Same thing in your browser at the point where you call the post/delete/put (presumably in a jquery request)


You can also unit test your controller methods: http://www.asp.net/mvc/tutorials/older-versions/unit-testing/creating-unit-tests-for-asp-net-mvc-applications-cs

Upvotes: 0

Related Questions