码迷,mamicode.com
首页 > Windows程序 > 详细

Core下简易WebApi

时间:2018-06-06 22:14:37      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ica   use   this   async   cal   exception   wait   config   rtu   

代码很粗糙~

粘贴github地址

https://github.com/htrlq/MiniAspNetCoreMini

demo

 1     public class Startup
 2     {
 3         public Startup(IConfiguration configuration)
 4         {
 5             Configuration = configuration;
 6         }
 7 
 8         public IConfiguration Configuration { get; }
 9 
10         // This method gets called by the runtime. Use this method to add services to the container.
11         public void ConfigureServices(IServiceCollection services)
12         {
13             services.AddMvc();
14 
15             services
16                 .AddApiServerInit()
17                 .AddApiServer<MyController>();
18         }
19 
20         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
22         {
23             if (env.IsDevelopment())
24             {
25                 app.UseDeveloperExceptionPage();
26             }
27 
28             app.UseMvc();
29 
30             app.UseRouter(route =>
31             {
32                 route.UserApiServer();
33             });
34         }
35     }
36 
37     public enum OrderSort
38     {
39         DoExecute,
40         Success,
41         NotPay
42     }
43 
44     public class ParamOrderSort
45     {
46         [Required]
47         public Guid? UserId { get; set; }
48         [Required]
49         public OrderSort? Type { get; set; }
50         public int? PageIndex { get; set; }
51         public int? PageSize { get; set; }
52     }
53 
54     public class MyController : ApiServerBase
55     {
56         [HttpGet]
57         [HttpPost]
58         public async Task Show(ParamOrderSort param)
59         {
60             await context.HttpContext.Response.WriteAsync($"{param.UserId} {param.Type} {param.PageIndex} {param.PageSize}");
61         }
62 
63         public MyController(IHttpContextAccessor context) : base(context)
64         {
65         }
66     }

 

Core下简易WebApi

标签:ica   use   this   async   cal   exception   wait   config   rtu   

原文地址:https://www.cnblogs.com/NCoreCoder/p/9146273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!