Annotation Type RequestAttribute


  • @Documented
    @Retention(RUNTIME)
    @Target({PARAMETER,TYPE,METHOD,ANNOTATION_TYPE})
    @Repeatable(RequestAttributes.class)
    @Bindable
    public @interface RequestAttribute

    An annotation that can be applied to method arguments to indicate that the method argument is bound to an HTTP request attribute This can also be used in conjuction with @RequestAttributes to list attributes on a client class that will always be applied Note: Request attributes are intended for internal data sharing only, and are not attached to the outbound request.

    The following example demonstrates usage at the type level to declare default values to pass in the request when using the Client annotation;

     @RequestAttribute(name = "X-Username", value = "Freddy"),
     @RequestAttribute(name = "X-MyParam", value = "${foo.bar}")
     @Client('/users')
     interface UserClient {
    
     }
     

    When declared as a binding annotation the @RequestAttribute annotation is declared on each parameter to be bound:

     @Get('/user')
     User get(@RequestAttribute('X-Username') String username, @RequestAttribute('X-MyParam') String myparam) {
        return new User(username, myparam);
     }
     
    Since:
    1.0
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.String defaultValue  
      java.lang.String name
      If used on a class level with @RequestAttributes this is the attribute name and value is the value.
      java.lang.String value
      If used as a bound parameter, this is the attribute name.
    • Element Detail

      • value

        @AliasFor(annotation=io.micronaut.core.bind.annotation.Bindable.class,
                  member="value")
        java.lang.String value
        If used as a bound parameter, this is the attribute name. If used on a class level this is value and not the attribute name.
        Returns:
        The name of the attribute, otherwise it is inferred from the parameter name
        Default:
        ""
      • name

        @AliasFor(annotation=io.micronaut.core.bind.annotation.Bindable.class,
                  member="value")
        java.lang.String name
        If used on a class level with @RequestAttributes this is the attribute name and value is the value.
        Returns:
        name of header when using with @RequestAttributes
        Default:
        ""
      • defaultValue

        @AliasFor(annotation=io.micronaut.core.bind.annotation.Bindable.class,
                  member="defaultValue")
        java.lang.String defaultValue
        Returns:
        The default value
        See Also:
        Bindable.defaultValue()
        Default:
        ""