5.4Defining Request Addresses

Created on Aug 17, 2026~2 min read

In the constructors of HttpMethodAttribute and its derived attributes, you can configure the request address. The following shows how to use these attributes in the IHttpService interface to define different request addresses:

cs
public interface IHttpService : IHttpDeclarative{    // Use a full URL address    [Get("https://furion.net/")]    Task<string> GetFullUrlMethodAsync();    // Use a relative address (without a leading slash)    [Get("api/get/user")]    Task<string> GetRelativeUrlMethod1Async();    // Use a relative address (with a leading slash)    [Get("/api/get/user")]    Task<string> GetRelativeUrlMethod2Async();    // The request address is an empty string; the actual request is BaseAddress    [Get("")]    Task<string> GetEmptyUrlMethodAsync();    // The request address is null; the actual request is BaseAddress    [Get(null)]    Task<string> GetNullUrlMethodAsync();    // The request address is null; the actual request is BaseAddress    [Get]    Task<string> GetNullUrlMethodAsync();}
  • When the provided request address is a complete URL, it is used directly as the final request address.
  • If the request address is a relative address (whether or not it includes a leading slash /), the framework attempts to combine it with the BaseAddress configured for HttpClient to generate the final request address. For example:
cs
services.AddHttpClient(string.Empty, client =>{    client.BaseAddress = new Uri("https://furion.net/");});

In the above configuration, if the request address is "api/get/user" or "/api/get/user", the final request address will be "https://furion.net/api/get/user".

  • If the request address is an empty string or null, the BaseAddress configured for HttpClient is used directly as the final request address. This means that if BaseAddress is "https://furion.net/", the final request address will also be "https://furion.net/".