Package io.micronaut.http.annotation
Annotation Interface 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 conjunction 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
- Author:
- Ahmed Lafta
-
Optional Element Summary
-
Element Details
-
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
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
- Returns:
- The default value
- See Also:
- Default:
- ""
-