In this article, we will understand how to utilize a famous developer productivity tool called Fiddler as REST API Test Client for SharePoint (though the target system could be anything with a valid REST API Endpoint).
Fiddler is primarily used as a Web Proxy that can allow you intercept REST API Request-Response Cycle. The usage of this tool has increased with the shift in modern SharePoint development paradigms that favors more the Client-Side Development Techniques/Strategies/Platforms rather than traditional Farm Solutions.
In this upcoming section of this article, I will guide on how to use Fiddler to test REST API Call against SharePoint Data.
In this article, we will explore GET type of requests only. To start with this demo, launch Fiddler and go to the “Rules” menu and select “Automatically Authenticate”. This will let Fiddler authenticate you against SharePoint based on the User Token stored once.
If this setting is not enabled, you might encounter “401 UNAUTHORIZED” as shown below.
Also, notice the request headers that are required to execute the SharePoint REST API Endpoint.
GET Requests http://<Host Name>/_api/<SharePoint Endpoint>
Request Headers accept: application/json;odata=verbose Content-Type: application/json;odata=verbose
Get Web Object http://<Host Name>/_api/web
- Click on “Compose” Tab.
- Select request type as “GET” from the dropdown.
- Specify the Request URL as http://<Host Name>/_api/web.
- Click on “Execute” button.
Once the request is issued using Fiddler “Composer“, we can see the request details in the left pane.
When you click on the request in the left pane, you see the details breakdown in the right-side pane.
For instance, we can click on “Inspectors” tab and then click on “JSON” tab. The JSON Tab will display the response received from SharePoint in JSON Format.
Similarly, we can execute other GET Requests as shown in the below images.
Get List Object http://<Host Name>/_api/Web/Lists
Get Lists which are not hidden and have Items
http://<Host Name>/_api/Web/Lists?$select=Title,Hidden,ItemCount&orderby=ItemCount&$filter=((Hidden eq false) and (ItemCount gt 0))
Encoded Version of Request URL
http://<Host Name>/_api/Web/Lists?$select=Title,Hidden,ItemCount&orderby=ItemCount&$filter=((Hidden%20eq%20false)%20and%20(ItemCount%20gt%200))
Get Web filtered by Title http://<Host Name>/_api/Web/?$select=Title
Get Web and Lists using Look Properties Expanding Lists Collection
http://<Host Name>/_api/Web/?$select=Title,Lists/Title,Lists/Hidden,Lists/ItemCount&$expand=Lists
Get Web and Lists using Look Properties Expanding Users Collection
http://sp-2016-ddev/_api/Web/?$select=Title,CurrentUser/Id,CurrentUser/Title&$expand=CurrentUser/Id
That is all for this demo.
Hope you find it helpful.