Click here to Skip to main content
11,640,626 members (60,036 online)
Click here to Skip to main content

Another Generic Util for Easily Testing REST Methods

, 14 Feb 2014 CPOL 4.5K 164 11
Rate this:
Please Sign up or sign in to vote.
Easily test REST methods that do not include args in routing attributes

How the Other Half Lives

I wrote an article here entitled "Use a Generic Util for Easily Testing REST Methods" that makes testing REST methods easy provided you incorporate the args passed via the URI into the server's routing attributes.

IOW, with Controller method routing attributes such as this:


...the client accesses the method annotated in that way with a URI such as:


Or for a literal/specific example:


This works fine and has the advantage of making the routing attribute on the server self-documenting. However, it does mix path/routing information (the "http://<serverName>:<portNum>/api/<ControllerName>" part) with args to be passed to the method (the "<serialNumVal>/<IDVal>/<CountToFetchVal>" part).

Therefore, I have created a new utility which allows for testing of methods that have routing attributes instead like this:


The method itself remains the same:

public IEnumerable<deliveryitem> GetRangeOfDeliveryItemsByStartingID(string serialNum, int ID, int CountToFetch)
    return _deliveryItemRepository.GetRange(string serialNum, ID, CountToFetch);

...but now it is called by the client this way:


<arg1Name>=<arg1Val>&<arg2Name>=<arg2Val> (etc.)

A literal example is:


-or, if there is a "differentiator" (name of a method to overcome any possible ambiguity):


Usage of the Util

To use the new Web API REST Tester utility, first you need to either save to file or add to the "Select a URI String" combo box entries in this format:

  • deliveries/Count
  • deliveries/GetAll
  • deliveries?ID={0}
  • deliveries?ID={0}&CountToFetch={1}
  • departments?serialNum={0}&ID={1}&CountToFetch={2}
  • InventoryItems?serialNum={0}&ID={1}&CountToFetch={2}&packSize={3}
  • InventoryItems/GetDeptRange?serialNum={0}&BeginDept={1}&EndDept={2}

IOW, Controller name, followed by Differentiator if there is one (such as "Count" or "GetAll"), followed by a question mark for the first arg, name of arg, equals sign, and "{0}". For subsequent args, an ampersand replaces the question mark and the number within the curly braces is incremented. The util will replace these "curly brace sandwich numbers" with values you add later.

Then, follow these steps (the step numbers correspond to what you see on the form):

0) Enter the "base uri" in the "Enter Base URI" textbox. This is something like "http://localhost:28642/api/"

1) if you saved the values to a text file, you can load it via the "Load URI Strings From File" button.

2) Select a value from the combo box.

3) Mash the "3) Discover URI Strings Args" button. This will visiblize a corresponding label and textbox where you can enter the value you want to use for each arg.

4) Enter values for each arg discovered:

5) Mash the "5) (Re)Build URI" button. It will build the URI to be passed to the server, replacing the placeholder vals with the values you entered in the text boxes, and displaying that in the textbox to the right of the "5) (Re)Build URI" button:

6) With the server running, as the Coup de grâce, mash the "6) Test the URI" button. If your code is right and the poles have not suddenly reversed and there was no giant electromagnetic storm, you will see the results displayed in the DataGridView below.

Note: The larger file is the entire project saved from Visual Studio via File > Export Template... The smaller file is the source code in a text file.

Subtle Hints, Supple Hands, and Desired Mints

If you like this article, take note that I am registered at Tiffany's (I have even breakfasted there on occasion!), and I've always wanted to "bling out," preferably with rubies, diamonds, sapphires, and lapis lazuli, not to mention scads of cubic zirconium. Just sayin'


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

B. Clay Shannon
Founder "Across Time & Space"
United States United States
Ideaman and Coder at Across Time & Space, creator of "Mark Twain Central" at

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction:

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 14 Feb 2014
Article Copyright 2014 by B. Clay Shannon
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid