A simple Test Client built on top of ASP.NET Web API Help Page
Step 1: Install the Test Client package
Install the WebApiTestClient package from the NuGet Package Manager. Make sure to “Include Prerelease” then just type in “WebApiTestClient” and click Install.

Once the package is installed, it will add the following files to your project:
- Scripts\WebApiTestClient.js
- Areas\HelpPage\TestClient.css
- Areas\HelpPage\Views\Help\DisplayTemplates\TestClientDialogs.cshtml
- Areas\HelpPage\Views\Help\DisplayTemplates\TestClientReferences.cshtml
It will also pull in the ASP.NET Web API Help Page package if it’s not already installed.
Step 2: Wire up the Test Client on Help Page
Open the file Api.cshtml (under Areas\HelpPage\Views\Help) and add the following:
- @Html.DisplayForModel("TestClientDialogs")
- @Html.DisplayForModel("TestClientReferences")
Note that you add the @Html.DisplayForModel("TestClientDialogs") after the <div> and @Html.DisplayForModel("TestClientReferences") inside the Scripts section.

You need to have the following JavaScript libraries installed. They should be installed if you used the default Web API template. Now, if you have different version numbers, you can update the references in TestClientReferences.cshtml.
- jQuery 1.7.1
- jQuery.UI.Combined 1.8.20
- knockoutjs 2.1.0
Once everything is wired up correctly, you should see the “Test API” button appearing on the bottom right corner of the API page.

Testing Web APIs
Now you can click on the “Test API” button to start testing the APIs. For each URI parameters, it will automatically provide a text box so that you can fill in the value instead of editing the URI. Note that the URI automatically gets updated as you fill in the parameter values.

After you click on Send, another dialog will pop up showing you the response.

Adding Request Headers
You can add additional request headers by clicking “Add Header”. For example, you can add the accept header “text/xml” to ask for XML.

And sure enough, your Web API returned the content as XML.

Providing Request Body
For methods like POST, you can provide the body in the Body section. Note that it will be prepopulated with the samples from Help Page so you don’t need to do any copy-pasting.

And you can select different samples based on the supported media types. For instance, selecting application/xml will pull in the XML sample. Note that the content-type and content-length headers are updated accordingly.

You can change the content of the body and the content-length header will change as you type!

Update: The source code is now hosted at: https://github.com/yaohuang/WebApiTestClient
A simple Test Client built on top of ASP.NET Web API Help Page的更多相关文章
- 使用ASP.NET Web API和Web API Client Gen使Angular 2应用程序的开发更加高效
		本文介绍“ 为ASP.NET Web API生成TypeScript客户端API ”,重点介绍Angular 2+代码示例和各自的SDLC.如果您正在开发.NET Core Web API后端,则可能 ... 
- [转]Getting started with ASP.NET Web API OData in 3 simple steps
		本文转自:https://blogs.msdn.microsoft.com/webdev/2013/01/29/getting-started-with-asp-net-web-api-odata-i ... 
- Dynamics 365 Online通过OAuth 2 Client Credential授权(Server-to-Server Authentication)后调用Web API
		微软动态CRM专家罗勇 ,回复332或者20190505可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 本文很多内容来自 John Towgood 撰写的Dynamic ... 
- Calling a Web API From a .NET Client (C#)
		on|January 20, 2014 1760 of 2013 people found this helpful Print Download Completed Project This tut ... 
- 利用Fiddler模拟通过Dynamics 365的OAuth 2 Client Credentials认证后调用Web API
		微软动态CRM专家罗勇 ,回复337或者20190521可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 配置Dynamics 365 & PowerApps 支 ... 
- NET Web API和Web API Client Gen使Angular 2应用程序
		使用ASP.NET Web API和Web API Client Gen使Angular 2应用程序的开发更加高效 本文介绍“ 为ASP.NET Web API生成TypeScript客户端API ” ... 
- offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、  Element.getBoundingClientRect()
		开篇提示:以下内容都经个人测试,参考API文档总结,但还是不能保证完全正确,若有错误,还请留言指出___________________________________________________ ... 
- Web API 自动生成帮助文档并使用Web API Test Client 测试
		之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ... 
- [WEB API] CLIENT 指定请求及回应格式(XML/JSON)
		[Web API] Client 指定请求及响应格式(xml/json) Web API 支持的格式请参考 http://www.asp.net/web-api/overview/formats-an ... 
随机推荐
- python语言学习6——python基础
			Python是一种计算机编程语言. 以#开头的语句是注释,注释是给人看的,可以是任意内容 其他每一行都是一个语句,当语句以冒号:结尾时,缩进的语句视为代码块. Python程序是大小写敏感的,如果写错 ... 
- hdu2102(bfs)
			题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 分析:bfs求最短时间到达'P'点,不过本题有好几个trick,我都踩到了,自己还是太嫩了... ... 
- linux下golang
			linux下golang的配置 linux下golang的配置 之前开发golang一直在windows下,今天在linux下试了一下 ,遇到一些梗,比如go 找不到 sync包.花了一小时全部解决, ... 
- 怎样让你的安卓手机瞬间变Firefox os 畅玩firefox os 应用
			Firefox os 手机迟迟不能在国内大面积上市.如今能买到的Firefox os手机国内就一款Firefox os ZET OPEN C ,但这款手机配置确实还不如人意.价格方面也不实惠,对于我们 ... 
- cocos2D-x 3.5 引擎解析之--引用计数(Ref),自己主动释放池(PoolManager),自己主动释放池管理器( AutoreleasePool)
			#include <CCRef.h> Ref is used for reference count manangement. If a classinherits from Ref. C ... 
- VMware workstation 安装错误提示1021解决方法
			Failed to create the requested registry key Key: Installer Error: 1021 解决方法:删除注册表--HKEY_LOCAL_MACHIN ... 
- IOS应用程序生命周期详解
			第一. IOS应用程序的五种状态: 1. Not running:应用还没有启动,或者应用正在运行但是途中被系统停止. 2. Inactive:当前应用正在前台运行,但是并不接收事件(当前或许正在执行 ... 
- Windows Phone开发(5):室内装修
			原文:Windows Phone开发(5):室内装修 为什么叫室内装修呢?呵呵,其实说的是布局,具体些嘛,就是在一个页面中,你如何去摆放你的控件,如何管理它们,你说,像不像我们刚搬进新住所,要&quo ... 
- MATLAB导入数据importdata功能
			用load函数导入mat文件大家都会.可是今天我拿到一个数据,文件后缀名竟然是'.data'.该怎么读呢? 我仅仅好用matlab界面Workspace区域的"import data&quo ... 
- abstract修改方法
			abstract这种方法修饰,主要用在抽象类和抽象方法. 抽象的类是不可实例化的比如 public abstract class Test{ } 他能够含有抽象的方法 public abstract ... 
