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的更多相关文章

  1. 使用ASP.NET Web API和Web API Client Gen使Angular 2应用程序的开发更加高效

    本文介绍“ 为ASP.NET Web API生成TypeScript客户端API ”,重点介绍Angular 2+代码示例和各自的SDLC.如果您正在开发.NET Core Web API后端,则可能 ...

  2. [转]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 ...

  3. Dynamics 365 Online通过OAuth 2 Client Credential授权(Server-to-Server Authentication)后调用Web API

    微软动态CRM专家罗勇 ,回复332或者20190505可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 本文很多内容来自 John Towgood 撰写的Dynamic ...

  4. 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 ...

  5. 利用Fiddler模拟通过Dynamics 365的OAuth 2 Client Credentials认证后调用Web API

    微软动态CRM专家罗勇 ,回复337或者20190521可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 配置Dynamics 365 & PowerApps 支 ...

  6. 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 ” ...

  7. offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、 Element.getBoundingClientRect()

    开篇提示:以下内容都经个人测试,参考API文档总结,但还是不能保证完全正确,若有错误,还请留言指出___________________________________________________ ...

  8. Web API 自动生成帮助文档并使用Web API Test Client 测试

    之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ...

  9. [WEB API] CLIENT 指定请求及回应格式(XML/JSON)

    [Web API] Client 指定请求及响应格式(xml/json) Web API 支持的格式请参考 http://www.asp.net/web-api/overview/formats-an ...

随机推荐

  1. OC -- 第一个类

    OC -- 第一个类 类名:Car 属性:轮胎个数.时速 行为:跑 完整写一个类:类的声明和实现 1.    类的声明 代码: // NSObject 再Foundation框架中 #import & ...

  2. Hlg 1832 【线段树 && RMQ】.cpp

    题意: 在给出的区间内求出最大买进卖出的差价. 思路: 对于弱数据:维护一个从左到右的最大差价和最小值.即当发现当前值比最小值小的时候更新最小值,否则看一下当前值与之前最小值的差价是否比最大差价大,是 ...

  3. Android 开源框架Universal-Image-Loader全然解析(二)--- 图片缓存策略具体解释

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/26810303),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...

  4. Deploy Oracle 10.2.0.5 DataGuard on Red Hat Enterprise Linux 6.4

    系统:Red Hat Enterprise Linux 6.4 数据库:Oracle 10.2.0.5.0 Patch Set 4 主机:10dg1 192.168.1.91 10dg2192.168 ...

  5. C++实现链栈的基本操作

    之前对顺序栈写了基本操作,认为有必要也动手练练栈的链表实现. 对于链栈,一般不会出现栈满的情况. 链栈头文件定义例如以下: #ifndef CSTOCK_H_ #define CSTOCK_H_ ty ...

  6. tar.bz2解压

    bzip2 -d gcc-4.1.0.tar.bz2 tar -xvf gcc-4.1.0.tar 或 tar -xvf *.tar

  7. Linux SSH端口转发

    SSH端口转发分为两种,一种是本地端口转发,又称为本地SSH隧道.一直是远程端口转发.SSH端口转发,还必须指定数据传送的目标主机,从而形成点对点的端口转发. 本地端口转发     假定有三台主机A. ...

  8. java获取日期之间的差异

    转载请注明出处.谢谢http://blog.csdn.net/harryweasley/article/details/42121485 当想到要计算差值.我们肯定想的是"2014.12.1 ...

  9. Codeforces Round #253 DIV1 C 馋

    http://codeforces.com/contest/442/problem/C 题意非常easy,基本上肯定有坑坑洼洼的样子.看题目案例,从第三个跟第二个没有凹的案例来看的话,多写几个以及多画 ...

  10. RPC分布式处理

    RPC(远程过程调用)的应用 接触背景 因为工作上某项目的需要设计一种分布式处理耗时的运算,每个节点然后将运算结果返回给中心服务器,而最初未了解RPC这部分之前我的设计是在每一个RPC服务器上搭建一个 ...