001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.http;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024/**
025 * Request bean annotation.
026 *
027 * <p>
028 * Identifies an interface to use to interact with HTTP parts of an HTTP request through a bean.
029 *
030 * <p>
031 * Can be used in the following locations:
032 * <ul>
033 *    <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods.
034 *    <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces.
035 * </ul>
036 *
037 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5>
038 * <p>
039 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as an interface for retrieving HTTP parts through a bean interface.
040 *
041 * <h5 class='section'>Example:</h5>
042 * <p class='bjava'>
043 *    <ja>@RestGet</ja>(<js>"/mypath/{p1}/{p2}/*"</js>)
044 *    <jk>public void</jk> myMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>) {...}
045 *
046 *    <jk>public interface</jk> MyRequest {
047 *
048 *       <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc>
049 *       String getP1();
050 *
051 *       <ja>@Path</ja>(<js>"p2"</js>)
052 *       String getX();
053 *
054 *       <ja>@Path</ja>(<js>"/*"</js>)
055 *       String getRemainder();
056 *
057 *       <ja>@Query</ja>
058 *       String getQ1();
059 *
060 *    <jc>// Schema-based query parameter:  Pipe-delimited lists of comma-delimited lists of integers.</jc>
061 *       <ja>@Query</ja>(
062 *          collectionFormat=<js>"pipes"</js>
063 *          items=<ja>@Items</ja>(
064 *             items=<ja>@SubItems</ja>(
065 *                collectionFormat=<js>"csv"</js>
066 *                type=<js>"integer"</js>
067 *             )
068 *          )
069 *       )
070 *       <jk>int</jk>[][] getQ3();
071 *
072 *       <ja>@Header</ja>(<js>"*"</js>)
073 *       Map&lt;String,Object&gt; getHeaders();
074 * </p>
075 * <p class='bjava'>
076 *    <jc>// Same as above but annotation defined on interface.</jc>
077 *    <ja>@RestGet</ja>(path=<js>"/mypath/{p1}/{p2}/*"</js>)
078 *    <jk>public void</jk> myMethod(MyRequest <jv>requestBean</jv>) {...}
079 *
080 * <ja>@Request</ja>
081 *    <jk>public interface</jk> MyRequest {...}
082 *
083 * <p>
084 * The return types of the getters must be the supported parameter types for the HTTP-part annotation used.
085 * <br>Schema-based serialization and parsing is allowed just as if used as individual parameter types.
086 *
087 *
088 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5>
089 * <p>
090 * Annotation applied to Java method arguments of interface proxies to denote a bean with remote resource annotations.
091 *
092 * <h5 class='section'>Example:</h5>
093 * <p class='bjava'>
094 *    <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>)
095 *    <jk>public interface</jk> MyProxy {
096 *
097 *       <ja>@RemoteGet</ja>(<js>"/mymethod/{p1}/{p2}"</js>)
098 *       String myProxyMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>);
099 *    }
100 *
101 *    <jk>public class</jk> MyRequest {
102 *
103 *       <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc>
104 *       <jk>public</jk> String getP1() {...}
105 *
106 *       <ja>@Path</ja>(<js>"p2"</js>)
107 *       <jk>public</jk> String getX() {...}
108 *
109 *       <ja>@Path</ja>(<js>"/*"</js>)
110 *       <jk>public</jk> String getRemainder() {...}
111 *
112 *       <ja>@Query</ja>
113 *       <jk>public</jk> String getQ1() {...}
114 *
115 *    <jc>// Schema-based query parameter:  Pipe-delimited lists of comma-delimited lists of integers.</jc>
116 *       <ja>@Query</ja>(
117 *          schema=<ja>@Query</ja>(
118 *             collectionFormat=<js>"pipes"</js>
119 *             items=<ja>@Items</ja>(
120 *                items=<ja>@SubItems</ja>(
121 *                   collectionFormat=<js>"csv"</js>
122 *                   type=<js>"integer"</js>
123 *                )
124 *             )
125 *          )
126 *       )
127 *       <jk>public</jk> <jk>int</jk>[][] getQ3() {...}
128 *
129 *       <ja>@Header</ja>(<js>"*"</js>)
130 *       <jk>public</jk> Map&lt;String,Object&gt; getHeaders() {...}
131 *    }
132 * </p>
133 *
134 * <h5 class='section'>See Also:</h5><ul>
135 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a>
136 * </ul>
137 * <p>
138 */
139@Documented
140@Target({ PARAMETER, TYPE, METHOD })
141@Retention(RUNTIME)
142@Inherited
143public @interface Request {
144
145   /**
146    * Optional description for the exposed API.
147    *
148    * @return The annotation value.
149    * @since 9.2.0
150    */
151   String[] description() default {};
152
153}