Udostępnij za pośrednictwem


StaticHeaderAttribute Class

Definition

Defines a static header to be sent on every API request.

public ref class StaticHeaderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true)]
[System.Diagnostics.Conditional("CODE_GENERATION_ATTRIBUTES")]
public sealed class StaticHeaderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true)>]
[<System.Diagnostics.Conditional("CODE_GENERATION_ATTRIBUTES")>]
type StaticHeaderAttribute = class
    inherit Attribute
Public NotInheritable Class StaticHeaderAttribute
Inherits Attribute
Inheritance
StaticHeaderAttribute
Attributes

Examples

[AutoClient("MyClient")]
[StaticHeader("X-MyHeader", "MyHeaderValue")]
interface IMyDependencyClient
{
    [Get("/api/users")]
    [StaticHeader("X-GetUsersHeader", "Value")]
    public Task<Users> GetUsers(CancellationToken cancellationToken = default);
}

Remarks

Injects a static header to be sent with every request. When this attribute is applied to an interface, then it impacts every method described by the interface. Otherwise, it only affects the method where it is applied. The header name must not be null or empty. The value, on the other hand, can be empty, but not null.

Constructors

StaticHeaderAttribute(String, String)

Initializes a new instance of the StaticHeaderAttribute class.

Properties

Header

Gets the name of the header.

Value

Gets the value of the header.

Applies to