简体   繁体   中英

How to use HttpGet in ASP.NET Core dynamic web api?

How to accept Verbs(Get) in ASP.NET Core dynamic web api?

Before

ABP(.NetFramework)

Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
.For<ITaskAppService>("tasksystem/task")
.ForMethod("GetTasks").WithVerb(HttpVerb.Get)
.Build();

New

ABP(ASP.NET Core)

  • You can use RemoteService attribute to enable/disable it for method or class level.

I don't know how to use RemoteService attribute, do you have any example code?

  • You can use any ASP.NET Core attributes to change HTTP methods or routes of the actions (but surely, this requires to add reference to related ASP.NET Core package).

I can't add Microsoft.AspNet.WebApi.Core to ABP 2.0.2 (ASP.NET Core), so I can't use [HttpGet].

Almost APIs use PostRequest, but need a little GetRequest for third-party. Thanks.

Ref: https://aspnetboilerplate.com/Pages/Documents/AspNet-Core#application-services-as-controllers

Add Microsoft.AspNetCore.Mvc.Core package instead.

using Microsoft.AspNetCore.Mvc.Core;

public class TaskAppService : ITaskAppService
{
    [HttpGet]
    public void MyMethod()
    {
    }
}

You should add the corresponding version of the package:

  • v1.1.5 for ASP.NET Core 1.x
  • v2.0.1 for ASP.NET Core 2.x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM