3.57Configuring the Request Base Address

Created on Aug 17, 2026~4 min read

When integrating with multiple third-party APIs, we usually register and configure the BaseAddress of multiple HttpClient instances globally. For example:

cs
// Configure the base address of the default clientservices.AddHttpClient(string.Empty, client =>{    client.BaseAddress = new Uri("https://furion.net/");});// Configure the base address of the GitHub clientservices.AddHttpClient("github", client =>{    client.BaseAddress = new Uri("https://github.com/");});

You can then specify the client to use via the .SetHttpClientName(client name) method.

In addition to global configuration, the framework also supports locally setting the base address for a single request, allowing it to be specified dynamically when building the request:

cs
// Set the base address using a stringHttpRequestBuilder.Get("/api/test")    .SetBaseAddress("https://furion.net");// Set the base address using a Uri objectHttpRequestBuilder.Get("/api/test")    .SetBaseAddress(new Uri("https://furion.net"));// Can be used as a prefixHttpRequestBuilder.Get("/api/test")    .SetBaseAddress("/furion");

Processing logic:

  • If the request address is an absolute address, the request is sent directly using that address.
  • If the request address is a relative address:
    • When no local BaseAddress is set, it is concatenated with the BaseAddress of the global HttpClient instance as the final request address.
    • When a local BaseAddress is set:
      • If the local BaseAddress is a relative address, the local BaseAddress is first concatenated before the request address, and then concatenated with the global BaseAddress.
      • If the local BaseAddress is an absolute address, that absolute address is concatenated directly with the request address as the final request address (the global BaseAddress is ignored in this case).