Skip to main content

Utility Beans

The org.apache.juneau.rest.beans package contains a set of reusable utility beans meant to help with putting together explorable REST interfaces.

The UtilityBeansResource class shows how these beans are used.

The resource class is hosted in the example REST applications rendered below:

ResourceDescriptions

The getChildDescriptions() method shows an example of rendering a list of descriptive links for child endpoints.

@RestGet("/")
public ResourceDescriptions getChildDescriptions() {
return ResourceDescriptions
.create()
.append("BeanDescription", "Example of BeanDescription bean")
.append("Hyperlink", "Example of Hyperlink bean")
.append("SeeOtherRoot", "Example of SeeOtherRoot bean");
}

HTML representation

Utility Beans HTML

JSON representation

Utility Beans JSON

BeanDescription

The aBeanDescription() method shows an example of rendering simple schema information about an arbitrary bean class.

@RestGet("/BeanDescription")
@HtmlDocConfig(
aside={
"",
" Example of serialized org.apache.juneau.rest.utilitybeans.BeanDescription bean.",
""
}
)
public BeanDescription aBeanDescription() {
return BeanDescription.of(Address.class);
}

HTML representation

Bean Description HTML

JSON representation

Bean Description JSON

The aHyperlink() method shows an example of rendering a simple hyperlink.

@RestGet("/Hyperlink")
@HtmlDocConfig(
aside={
"",
" Example of serialized org.apache.juneau.rest.utilitybeans.Hyperlink bean.",
""
}
)
public Hyperlink aHyperlink() {
return Hyperlink.create("/utilitybeans", "Back to /utilitybeans");
}

HTML representation

Hyperlink HTML

JSON representation

Hyperlink JSON

SeeOtherRoot

The aSeeOtherRoot() method shows an example of sending a 303 See Other with a Location header pointing to the servlet root.

@RestGet("/SeeOtherRoot")
@HtmlDocConfig(
aside={
"",
" Example of serialized org.apache.juneau.rest.utilitybeans.SeeOtherRoot bean.",
""
}
)
public SeeOtherRoot aSeeOtherRoot() {
return SeeOtherRoot.INSTANCE;
}

Clicking on the link will just redirect to this same page.

Typically this is useful for endpoints where you want to redirect back to the servlet root, such as a DELETE.