【swaggerui】swaggerui在asp.net web api core 中的应用
Swaggerui 可以为我们的webapi提供美观的在线文档,如下图:

实现步骤:
- NuGet Packages Install-Package Swashbuckle.AspNetCore
- 在startup文件中配置swagger
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "ToDo API",
Description = "A simple example ASP.NET Core Web API",
TermsOfService = "None",
Contact = new Contact { Name = "Shayne Boyer", Email = "", Url = "https://twitter.com/spboyer" },
License = new License { Name = "Use under LICX", Url = "https://example.com/license" }
}); //Set the comments path for the swagger json and ui.
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, "MyWebApiCore.xml");
c.IncludeXmlComments(xmlPath);
});
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(); app.UseMvc();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}
- XML Comments,点击项目属性=》生成=》XML文档文件打勾,然后在你的action上添加注释
/// <summary>
/// Get方法无参数
/// </summary>
/// <returns>string[]数组</returns>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}/// <summary>
/// 根据id获取
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <remarks>
/// Note that the id is an integer.
/// </remarks>
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
} - 运行项目,输入文档地址http://localhost:58911/swagger/
你可以选择方法进行在线测试

【swaggerui】swaggerui在asp.net web api core 中的应用的更多相关文章
- swaggerui在asp.net web api core 中的应用
Swaggerui 可以为我们的webapi提供美观的在线文档,如下图: 实现步骤: NuGet Packages Install-Package Swashbuckle.AspNetCore 在s ...
- ASP.NET Web API 2 中的属性路由使用(转载)
转载地址:ASP.NET Web API 2 中的属性路由使用
- 在ASP.NET Web API项目中使用Hangfire实现后台任务处理
当前项目中有这样一个需求:由前端用户的一个操作,需要触发到不同设备的消息推送.由于推送这个具体功能,我们采用了第三方的服务.而这个服务调用有时候可能会有延时,为此,我们希望将消息推送与用户前端操作实现 ...
- 在ASP.NET Web API 2中使用Owin基于Token令牌的身份验证
基于令牌的身份验证 基于令牌的身份验证主要区别于以前常用的常用的基于cookie的身份验证,基于cookie的身份验证在B/S架构中使用比较多,但是在Web Api中因其特殊性,基于cookie的身份 ...
- ASP.NET Web API 2 中的特性路由
ASP.NET MVC 5.1 开始已经支持基于特性的路由(http://attributerouting.net),ASP.NET WEB API 2 同时也支持了这一特性. 启用特性路 由只需要在 ...
- ASP.NET Web API 2中的错误处理
前几天在webapi项目中遇到一个问题:Controller构造函数中抛出异常时全局过滤器捕获不到,于是网搜一把写下这篇博客作为总结. HttpResponseException 通常在WebAPI的 ...
- [翻译]ASP.NET Web API 2 中的全局错误处理
目录 已存在的选项 解决方案预览 设计原则 什么时候去用 方案详情 示例 附录: 基类详情 原文链接 Global Error Handling in ASP.NET Web API 2 由于翻译水平 ...
- 在ASP.NET Web API 2中使用Owin OAuth 刷新令牌(示例代码)
在上篇文章介绍了Web Api中使用令牌进行授权的后端实现方法,基于WebApi2和OWIN OAuth实现了获取access token,使用token访问需授权的资源信息.本文将介绍在Web Ap ...
- ASP.NET Web API 2中的属性路由(Attribute Routing)
如何启用属性路由并描述属性路由的各种选项? Why Attribute Routing? Web API的第一个版本使用基于约定的路由.在这种类型的路由中,您可以定义一个或多个路由模板,这些模板基本上 ...
随机推荐
- 四、新时间日期API
一.使用 LocalDate .LocalTime .LocalDateTime LocalDate.LocalTime.LocalDateTime 类的实例是不可变的对象,分别表示使用 ISO-86 ...
- EF SQLite的Like语句,生成为CHARINDEX的解决办法
在使用EF SQLite的时候发现Like语句不能完全查询出来,看了下生成的SQL语句类似于这种 (CHARINDEX(@p__linq__2, [Extent1].[LeagueName])) &g ...
- textview的阴影线
android:shadowColor="#000000" android:shadowDx="1" android:shadowDy="1" ...
- 手机APP测试如何进行兼容性测试?
Android App兼容性测试是一个比较重要的App评价内容,实际上兼容性测试不仅仅和测试人员相关,在开发阶段就应当着重考虑,因为兼容性问题是除了实现App本身要求的功能后,必须要关注.而且至关重要 ...
- 82. Single Number [easy]
Description Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1, ...
- 怎么给kibana加上权限?
更新:2016-05-20 09:36 通过向Elastic了解,他们目前开发的5.0版本支持更好的权限定制,粒度达到字段级别.他们预计今年就可以上线,如果你不是有一个旧版本的kibanba非要维护不 ...
- Hadoop第一课:Hadoop集群环境搭建
一. 检查列表 1.1.网络访问 设置电脑IP以及可以访问网络设置:进入etc/sysconfig/network-scripts/,使用命令“ls -all” 查看文件.会看到ifcfg-lo文件然 ...
- 贵州省未来二十年的投资机会的探讨1>
贵州的股市 1.000540.SZ 中天金融 2.000589.SZ 黔轮胎A 3.000733.SZ 振华科技 4.000851.SZ 高鸿股份 5.000920.SZ 南方汇通 6.002025. ...
- Python3 标准库:calendar,time
1.calendar import calendar print(calendar.month(2008,8)) #某个月 print(calendar.calendar(2008)) #某年 pri ...
- [leetcode-784-Letter Case Permutation]
Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...