How To Use Fiddler With ASP.NET Web API Testing

Part 1 - Manual testing with Fiddler

ASP.NET

If you are developer, tester, or a manager, sometimes understanding the various methods of API can be a challenge when building and consuming the application.

Generating good documentation and help pages for your Web API, using Fiddler with .NET  is as easy as making some HTTP calls.

Let’s start by downloading simple To-do projects from GitHub.

Download and run the below TodoMvcSolution from below link.

ASP.NET
    Download Fiddler

    Fiddler is one of the best tools for analyzing and testing network traffic including Web API calls.

    You can download and install Fiddler from below web site.

    Here is the APIs we want to test; Get, Post, Put and Delete for this application.

    ASP.NET

    Here are the Web APIs we want to test.

    1. //Copyright 2017 (c) SmartIT. All rights reserved.  
    2. //By John Kocer  
    3. // This file is for Swagger test, this application does not use this file  
    4. using System.Collections.Generic;  
    5. using Microsoft.AspNetCore.Mvc;  
    6. using SmartIT.Employee.MockDB;   
    7.   
    8. namespace TodoAngular.Ui.Controllers  
    9. {  
    10.   [Produces("application/json")]  
    11.   [Route("api/Todo")]  
    12.   public class TodoApiController : Controller  
    13.   {  
    14.     TodoRepository _todoRepository = new TodoRepository();  
    15.   
    16.     [Route("~/api/GetAllTodos")]  
    17.     [HttpGet]  
    18.     public IEnumerable<SmartIT.Employee.MockDB.Todo> GetAllTodos()  
    19.     {  
    20.       return _todoRepository.GetAll();  
    21.     }  
    22.   
    23.     [Route("~/api/AddTodo")]  
    24.     [HttpPost]  
    25.     public SmartIT.Employee.MockDB.Todo AddTodo([FromBody]SmartIT.Employee.MockDB.Todo item)  
    26.     {  
    27.       return _todoRepository.Add(item);  
    28.     }  
    29.   
    30.     [Route("~/api/UpdateTodo")]  
    31.     [HttpPut]  
    32.     public SmartIT.Employee.MockDB.Todo UpdateTodo([FromBody]SmartIT.Employee.MockDB.Todo item)  
    33.     {  
    34.       return  _todoRepository.Update(item);  
    35.     }  
    36.   
    37.     [Route("~/api/DeleteTodo/{id}")]  
    38.     [HttpDelete]  
    39.     public void Delete(int id)  
    40.     {  
    41.       var findTodo = _todoRepository.FindById(id);  
    42.       if (findTodo != null)  
    43.         _todoRepository.Delete(findTodo);  
    44.     }  
    45.   }  

    Note

    Your local port number may be different than our, use your local port number.

    • http://localhost:63274/api/GetAllTodos // GET
    • http://localhost:63274/api/AddTodo //POST
    • http://localhost:63274/api/UpdateTodo //PUT
    • http://localhost:63274/api/DeleteTodo/5 // DELETE
    Testing GET with Fiddler
    • Testing GET is very easy.
    • First, we need to click Composer tab on the Fiddler app.
    • Next, select Parsed tab below the Execute line.
    • Then, set Http Action from the dropdown list as GET.
    • Then, we need to type or paste into the API URL box;
      http://localhost:63274/api/GetAllTodos
    • Then, click Execute. 

      ASP.NET

    To see the resold version, we need to double click our API link on the Progress Telerik Fiddler Web Debugger window.

    If the GET is successful, we see the status: 200 OK. 

    ASP.NET

    This will bring the Fiddler -Detail View with GET information loaded like below. We have to make sure to select correct tabs to see the return list.

    To see what we sent as Raw: MENU: Inspectors >> Raw Tab .
    To see to response as Raw: Response Raw Tab.

    ASP.NET

    Testing POST with Fiddler

    • First, we need to set Http Action from the dropdown list as POST.
    • Then, we need to type or paste into the API URL box.
    • AddTodo API accepts a Todo object in JSON format. We need to pass a new Todo JSON data.
      http://localhost:63274/api/AddTodo
    • To pass JSON data we need to Select Body Tap.
    • Select the Raw
    • Add Content-Type: application/json into post request option under Host.
    • Write or paste your Todo JSON data.
      1. {  
      2.     "id": 0,  
      3.     "name""Order an Amazon Alexa"  
      4. }  
    • Then, click the Execute.

      ASP.NET

    If the GET successful we see the status: 200 OK. 

    You will see Status:200 for success and the return value in the Return Body Tap. We send Publish Fiddler Todo item with id=0 and we received id=5 as result.

    ASP.NET

    Testing PUT with Fiddler

    • First, we need to set Http Action from the dropdown list.
    • Then, we need to type or paste into the API URL.
      http://localhost:63274/api/UpdateTodo
    • UpdateTodo API accepts a Todo object in JSON format. We need to pass an existing Todo JSON data.
    • To pass JSON data we need to Select Body Tab.
    • Select the Raw format.
    • Add Content-Type: application/json into post request option under Host.
    • Write or paste your Todo JSON.
      1. {  
      2.     "id": 5,  
      3.     "name""Order an Amazon Alexa-DONE"  
      4. }  
    • Then click the blue Execute

      ASP.NET

    If the GET is successful, we see the status: 200 OK.  

    ASP.NET

    You will see Status:200 for success and the return value in the Return Body Tap. We send Publish Fiddler Todo item with "name": " Order an Amazon Alexa-DONE " we received updated todo result.

    ASP.NET

    Testing DELETE with Fiddler

    • First, we need to set Http Action from the dropdown list as DELETE.
    • Then, we need to type or paste into the API URL box.
    • DeleteTodo/5 API accepts an id on the  We need to pass an existing Todo with and Id value.
    • Then, click Execute.

      ASP.NET  

    If the GET is successful, we see the status: 200 OK. 

    ASP.NET

    This will complete the Fiddler tutorial.

    Summary

    In this article, we have learned how to use Fiddler with ASP.NET Core Web APIs. Download the source code from GitHub.

    Thank you for reading this article. You may be interested in reading the below training articles too.

    Up Next
      Ebook Download
      View all
      Learn
      View all