5.35Removing the Trailing / from the URL Address

Updated on Aug 20, 2026~3 min read

Some servers are sensitive to a trailing / in the path (such as /api/ versus /api), which may cause a 301 redirect or route matching failure. When this feature is enabled, the framework automatically removes the trailing / from the path when constructing the final request address.

HTTP declarative requests remove the trailing / from the URL address through the RemoveTrailingSlashAttribute attribute. The corresponding HTTP declarative extractor implementation is the RemoveTrailingSlashDeclarativeExtractor type, which is responsible for parsing the RemoveTrailingSlashAttribute attribute and building the configuration required by the HttpRequestBuilder instance to remove the trailing / from the URL address.

cs
// Applied at the interface definition, affecting all methods[RemoveTrailingSlash]public interface IHttpService : IHttpDeclarative{    // Applied at the method level    [RemoveTrailingSlash]    [Get("https://furion.net/")]    Task<string> GetStringAsync();    [RemoveTrailingSlash(false)]   // Disable this feature    [Get("https://furion.net/")]    Task<string> GetStringAsync();}

The request address becomes https://furion.net.

RemoveTrailingSlashAttribute contains the following constructors and properties:

  • Constructors:

    • new(): Applies to methods or interfaces, removing the trailing / from the URL address.
    • new(enabled): Applies to methods or interfaces, setting whether the trailing / is removed from the URL address.
  • Properties:

    • Enabled: Whether it is enabled (bool type), defaulting to true (enabled).