0

This is my first attempt at using the asp.net web api.

I've tried running it in debug mode but I'm not sure what to browse to. Can I just drop a url in my browser or do I have to create a special http get request with fancy headers or something? I just want to see that my web api controller is returning a list of stuff when I browse to it.

Any help/guidance is appreciated.

Note: I'm not using MVC, it's just an empty web application with a web api controller class added to it.

3
  • Try Fiddler. Create request using it, you can pass json/xml object and check the returned value as well. Also check out this. It has Calling the Web API with Javascript and jQuery, Browser etc
    – Habib
    Commented Oct 25, 2012 at 5:27
  • @Habib I've got fiddler open and can send http get requests with a content type of text/json but my problem is I don't know where I'm supposed to send the request to. The article you linked to creates a web api project, I just have an empty one that I added a controller class to - is there another step I need to do?
    – Dean
    Commented Oct 25, 2012 at 5:51
  • 1
    I would suggest you to use Web API project template, instead of starting up with the new empty project. You may follow the linked article and then later if you feel comfortable, start up with an empty project
    – Habib
    Commented Oct 25, 2012 at 5:53

2 Answers 2

1

I needed to add the following usings to my global.asax file

using System.Web.Routing;
using System.Web.Http;

and then add:

protected void Application_Start(object sender, EventArgs e)
{
    RouteTable.Routes.MapHttpRoute(
        name: "API Default",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}

Thanks marco709394 for pointing me in the right direction and Habib for making the sensible suggestion to just create a new web api project - but unfortunately I'm required to add web api to an existing asp.net 4.0 web application.

0

You can just simply browse to the url corresponding to your controller for a get request

2
  • How do I know what the corresponding url is?
    – Dean
    Commented Oct 25, 2012 at 5:45
  • 1
    you should be able to simply add the RouteTable.Routes.MapHttpRoute in Application_Start to define the url Commented Oct 25, 2012 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.