The {@link oaj.http.annotation.Request @Request} annotation can used to define proxy interfaces against
HTTP requests in combination with the following annotations used on methods:
- {@link oaj.http.annotation.Header}
- {@link oaj.http.annotation.Query}
- {@link oaj.http.annotation.FormData}
- {@link oaj.http.annotation.Path}
- {@link oaj.http.annotation.Content}
- {@link oaj.annotation.Schema}
| @RestPut("/pets/{petId}")
| public void addPet(UpdatePetBean updatePet) {...}
|
| @Request
| public interface UpdatePetBean {
|
| @Path // {petId} inferred.
| int getPetId();
|
| @Query("verbose")
| boolean isDebug();
|
| @Header("*")
| Map<String,Object> getAllHeaders();
|
| @Content
| Pet getPet();
| }
The example above is identical in behavior to specifying individual annotated parameters on the @RestOp-annotated method:
| @RestPut("/pets/{petId}")
| public void addPet(
| @Path("petId") int petId,
| @Query("verbose") boolean debug,
| @Header("*") Map<String,Object> allHeaders,
| @Content UpdatePetBean pet
| )
| {...}
The return types of the getters must be the supported parameter types for the HTTP-part annotation used.
Schema-based serialization and parsing is used just as if used as individual parameter types.
Annotations used are the exact same used on REST parameters and have all the
same feature support including automatic Swagger validation and documentation.
Part names can either be explicitly specified or automatically inferred from the getter names.
| @Request
| public interface MyRequest {
|
| // Schema-based query parameter "pipedCdlInts":
| // Pipe-delimited list of comma-delimited lists of integers.
| @Query
| @Schema(
| collectionFormat="pipes"
| items=@Items(
| items=@SubItems(
| collectionFormat="csv"
| type="integer",
| minimum=1,
| maximum=100
| ),
| maximumLength=10
| )
| )
| int[][] getPipedCdlInts();
| }
For clarity, the @Request annotation can be defined on the parameter, class, or both.
| @RestPut("/pets/{petId}")
| public void addPet(@Request UpdatePetBean updatePet) {...}
|
| @Request
| public interface UpdatePetBean {...}