Using Postman to test a GET Request in a Visual Studio API

Sherry Hall
2 min readDec 13, 2016

--

To Start:
• Open your Google Chrome browser and go to https://www.getpostman.com/
• Download and install the Chrome App
• Sign up for a Postman logon ID.

To Test your API:
Start Postman — open the Google Chrome browser, click the “Show Apps” icon on the favorites bar, then click the Postman icon. On the resulting Postman page, note the line in the top, middle portion of the page comprised of a drop-down (GET, POST, etc.), a URL entry field, a “Params” button, and “Send” button. Set the drop-down to GET.

In Visual Studio, open the project for your completed API and start it using Google Chrome. This will create a web page tab in Chrome. Copy the URL from the address bar and paste it into the URL entry field on the Postman page noted in the paragraph above. The URL should look similar to http://localhost:49606/ where 49606 is the port number, which will vary for each project.

After the pasted URL, add “api/” followed by the name of the controller you are testing. For example, if I am testing CatalogController.cs in the Controllers folder of my API, the resulting URL would look like —
http://localhost:49606/api/Catalog.

Click the “Send” button. This will execute the GET method in the Catalog controller which does not have any parameters. For Example:
In Postman — GET http://localhost:49606/api/Catalog
Will execute

[HttpGet]
public IHttpActionResult GetAllBooks()
{
. . .;
return Ok();
}

If you are testing a GET request with parameters, add a “?” after the control name, followed by the parameters in the form “variable name=value”. If you have more than one parameter, separate them by “&”. For Example:
In Postman — GET http://localhost:49606/api/Catalog& ?IsCheckedOut=false
Will execute

[HttpGet]
public IHttpActionResult GetBooksByStatus(bool IsCheckedOut)
{
. . . ;
return Ok();
}

Note that the parameters listed in the Postman URL must match the number and type in the controller’s method that you are testing. You can also view and enter the parameters in a more user-friendly manner by clicking the “Params” button.

By changing the drop-down, you can also test other types of API requests:
POST will execute [HttpPost] methods for updating.
PUT will execute [HttpPut] methods for adding.
DELETE will execute [HttpDelete] methods for deleting.

--

--