Abp: Auto api

Created on 11 Jun 2020  路  4Comments  路  Source: abpframework/abp

image
According to the document

If the method has an 'id' parameter then it adds '/{id}' ro the route.

I wonder if I can change it to "code" then it adds '/{code}'.

question

Most helpful comment

Another way for you :)

private void ConfigureConventionalControllers()
{
    Configure<AbpAspNetCoreMvcOptions>(options =>
    {
        options.ConventionalControllers.Create(typeof(MyProjectApplicationModule).Assembly, opt =>
        {
            opt.UrlActionNameNormalizer = context =>
            {
                if (context.ControllerName == "AdminUser" && context.Action.ActionMethod.Name == "GetAdminUserAndStationAsync")
                {
                    return "{code}/adminUserAndStationAsync";
                }
                return null;
            };
        });
    }
}

All 4 comments

yes,you can, just do it

change all id to code

If you want to keep the Auto API Controller feature working and customize an API's route, the simple way is adding [Route("your custom route")] attribute to the method of the application service class.

If you want to follow the best practice:

  1. Add [RemoteService(false)] attribute to the method of the application service class.
  2. Create a controller manually. See the demo.

For more information: https://docs.abp.io/en/abp/latest/API/Auto-API-Controllers

Another way for you :)

private void ConfigureConventionalControllers()
{
    Configure<AbpAspNetCoreMvcOptions>(options =>
    {
        options.ConventionalControllers.Create(typeof(MyProjectApplicationModule).Assembly, opt =>
        {
            opt.UrlActionNameNormalizer = context =>
            {
                if (context.ControllerName == "AdminUser" && context.Action.ActionMethod.Name == "GetAdminUserAndStationAsync")
                {
                    return "{code}/adminUserAndStationAsync";
                }
                return null;
            };
        });
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChangYinShung picture ChangYinShung  路  3Comments

ugurozturk picture ugurozturk  路  3Comments

derily picture derily  路  3Comments

hikalkan picture hikalkan  路  3Comments

leonkosak picture leonkosak  路  3Comments