Skip to main content

@Request

The @Request annotation can be applied to a type of a @RemoteOp-annotated method to identify it as a bean for setting HTTP parts through a bean-like interface.

Requestserializer - Override the part serializer.
Example
@Remote(path="/petstore")
public interface PetStore {

@RemotePost
String postPet(CreatePetRequest bean);
}
@Request
public class CreatePetRequest {

private CreatePet pet;

public CreatePetRequest(String name, float price) {
this.pet = new CreatePet(name, price);
}

@Content
public CreatePet getContent() {
return this.pet;
}

@Query
public Map getQueryParams() {
return AMap.of("debug", true);
}

@Header("E-Tag")
public static UUID getUUID() {
return UUID.generatedUUID();
}
}
PetStore store = client.getRemote(PetStore.class, "http://localhost:10000");

CreatePetRequest requestBean = new CreatePetRequest("Fluffy", 9.99);
String response = store.postPet(requestBean);

The @Request annotation can be applied to either the class or argument. The annotated methods must be no-arg and public. They can be named anything. Any of the following annotations can be used on the methods:

ContentHeaderFormDataQueryPath

The behavior and functionality of all of the annotations are the same as if they were used on method arguments directly. This means full support for OpenAPI serialization and validation. Annotations on methods are inherited from parent classes and interfaces. For example, the request bean above could have defined annotations in an interface to keep them clear from the implementation:

<a href="/site/apidocs/org/apache/juneau/http/annotation/Request.html" target="_blank">@Request</a>
public interface CreatePetRequest {

@Content
CreatePet getContent();

@Query
Map getQueryParams();

@Header("E-Tag")
UUID getUUID();
}
public class CreatePetRequestImpl implements CreatePetRequest {

public CreatePetRequestImpl(String name, float price) {...}

@Override
public CreatePet getContent() {
return this.pet;
}

@Override
public Map getQueryParams() {
return JsonMap.of("debug", true);
}

@Override
public UUID getUUID() {
return UUID.generateUUID();
}
}