Base solution for your next web application
Open Closed

Programmatically retrieve API route #5332


User avatar
0
kiandra created

Hello,

Is it possible to programmatically retrieve the URL of an AppService method from another AppService method? For example:

public class ActionsAppService: MyAppServiceBase, IAppService {
        
    [AbpAuthorize(AppPermissions.Pages_Actions_Edit)]
    public async Task<GetActionForEditOutput> GetActionForCreate(string actionType)
    {
        var action= new Action();

        action.PostbackUrl = [SOMETHING TO RETRIEVE URL OF THE POSTBACK METHOD BELOW];

        return action;
    }

    //This will be called by an external system
    public async Task PostBack(string formData){
        ....
    }
}

Cheers, Brad Webber


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    What is the reason for you to do this?

  • User Avatar
    0
    kiandra created

    I need to present the user with a URL that they can use in a separate application so that they can post some data back to my application.

  • User Avatar
    0
    maliming created
    Support Team

    Are you using ABP's dynamic API? If so, the application service will be exposed as a WebAPI And the routing url of the application service is regular. [https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API])

    Such as: '/api/services/app/actions/GetActionForCreate', '/api/services/app/actions/PostBack' '/api/services/app/otheractions/PostBack'

  • User Avatar
    0
    kiandra created

    I am using the dynamic API, however I was hoping to avoid hard-coding the url that I return.

  • User Avatar
    0
    maliming created
    Support Team

    You can get all the information of the dynamic API in the AbpAspNetCoreConfiguration property of IAbpAspNetCoreConfiguration. [https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Configuration/AbpAspNetCoreConfiguration.cs#L21])

    ABP also generates dynamic APIs from this information, just doing this will be more complicated. If you don't easily change the moduleName of the dynamic API, etc. Hard coding is the easiest.

    I don't know your specific situation, maybe there are other ways to fulfill your needs.

  • User Avatar
    0
    alper created
    Support Team

    ApplicationService has no Web dependent reference. But you can use IWebUrlService to get the website root address. So you can build the WebApi URL. Hope that helps...

    To see this link you have to be logged in GitHub <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/0619e6f8ce314963135a7220fe1d447138361bf3/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application/Authorization/Accounts/AccountAppService.cs#L34">https://github.com/aspnetzero/aspnet-ze ... ice.cs#L34</a>