3

I have a web api method:

 [HttpPost, ActionName("GET")]
        public string Get(string apiKey, DateTime start, DateTime end)
        {
            var user = db.Users.SingleOrDefault(u => u.Id == apiKey);

            if (user == null)
            {
                return string.Empty;
            }

            var records = db.Histories.Where(h => h.Date >= start && h.Date <= end);
            return JsonConvert.SerializeObject(records);
        }

And here is the url I tried to call the method, but it doesn't reach to the method.

http://localhost:11847/api/History/Get?apiKey=398cfa9b-8c5c-4cf4-b4f3-8904a827ff22&start=2014-01-01&end=2014-12-01

I also have changed the WebApiConfig.cs

   config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}",
                defaults: new { id = RouteParameter.Optional }
            );

from "api/{controller}/{id} to "api/{controller}/{action}

2 Answers 2

6

UPDATE 2022: It's 2022 now. A lot has changed. There are plenty of clients out there. I will list my favourites.

  1. Postman - Postman has improved since I answered this in 2014. Apart from being a client, it has other features like collaboration, scripting, importing endpoints from various sources like Open API etc. Pretty simple to use.

  2. Thunder Client - A Visual Studio extension that has a similar feel as Postman but a pure API client.


For testing the api, you can use fiddler(http://www.telerik.com/fiddler) or a chrome app called postman.

enter image description here

You should also try the POSTMAN by http://www.getpostman.com/ which can be added to chrome as an app. It really good and lets you organize your apis.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm using Fiddler. I just don't know how to write the url in the Fiddler
How to write the url in Fiddler?
If fiddler is overwhelming use Chromes app POSTMAN which I use. It's simple and easy.
+1 for POSTMAN. It is very good tool for testing the methods
Hi DanKodi, I reviewed my question and your answer and found that your post answers my question(while mine only answers the my question in the comment). So I marked yours as my answer :)
1

I found out how to write the url in Fiddler:

In the Composer panel:

Parsed:
GET : http://localhost:11847/api/History/GetRecords?apiKey=398cfa9b-8c5c-4cf4-b4f3-8904a827ff22&start=2014-01-01&end=2014-12-01

Request Headers:
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:11847
Content-Length: 0

Comments

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.