Open Closed

How does Web Front End consume the HttpAPI.Host in a tiered application? #616


User avatar
0
Jmg0g0 created
  • ABP Framework version: v3.3.1
  • UI type: MVC/ Razor pages
  • Tiered (MVC) or Identity Server Seperated (Angular): yes

Dear support team, I have a question about communication between FrontEnd (Razor page) & Web API. The example use: abp new Sample.Tiered --tiered to create a sample application with 3 executables (Web, HttpAPI.Host and IdentityServer).

I that situation, my expectations are comsume the HttpAPI.Host from Web in every request. To test it, I followed this tutorial, to up & running the application.

The test is to create a Create Tenant request and confirm the behavior of the application. After executed the request, the log shows me this output in the Front End (Web)

Inside the red frame, the log entry says: [06:26:28 INF] Executing handler method Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants.CreateModalModel.OnPostAsync - ModelState is Valid. If you follow OnPostAsync of the TenantManagement Module. The method CreateAsync in the ApplicationService TenantAppService will be execute with the corresponding logic call to repositories, unit of work and save to persistence. Probably, this call is redirected to API, blocked or something but I cannot see.

And, the next entry in the log is: [06:26:28 INF] Start processing HTTP request POST https://localhost:44372/api/multi-tenancy/tenants?api-version=1.0 As I expected, a request to the web API for processing the CreateAsync

Where is this request iniciated against the HttpAPI?

From the HttpAPI point of view, you can see the piece of log in the next image, the API is processing the request using a controller calling the method CreateAsync in the ApplicationService TenantAppService and so on.

Is the application behavior trying to execute CreateAsync method in the TenantAppService of the TenantManagement Module twice?, one in the Front End and the other in the HttpAPI request.

Obiously, If you inspect the database, only one tenant is created, then I need to understand how this request is working and how the first call to CreateAsync method is redirected to the web API.

Hopefully, I explanied well, if not, please let me know. Thanks, Jose


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Web project use dynamic C# API clieint proxy to send HTTP Request. See https://docs.abp.io/en/abp/latest/API/Dynamic-CSharp-API-Clients

    The front end send a request to the back end HTTP API endpont.

  • User Avatar
    0
    Jmg0g0 created

    Thanks liangshiwei, My name is Jose, Ok, the link that you send makes sense for me, I had read before but it's not always easy to get the right direction.

    As a summary, the call from the Front End to the application service is intercepted by the HttpClient and redirected to HttpAPI.Host endpoint. Correct?

    Therefore, could we say that the call to the method CreateAsync from the Post request of the client razor page it's not executed?

    And, please, could you point me to the code where this magic is done?, is it a middleware injected into the request pipeline?

    ~~At last, but not least is it the code behind PostAsync Method of my razor page (or in this case the Tenant Management module) executed?~~

    Thanks so much, Jose

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Therefore, could we say that the call to the method CreateAsync from the Post request of the client razor page it's not executed?

    It executed, by using HttpClient to send a request to HttpApi.Host.

    And, please, could you point me to the code where this magic is done?, is it a middleware injected into the request pipeline?

    It is not middleware, you can understand it as an implementation of proxy mode, abp replaces the implementation of the application service interface with the proxy implementation, build and sends Http requests according to the API description and interface signature.

    DynamicHttpProxyInterceptor is the core class of dynamic proxy

  • User Avatar
    0
    Jmg0g0 created

    So much clear now, I appreciated so much your support.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07