{title:'Child Resources', updated:'9.0.0'}

Child Resources are REST servlets or objects that are linked to parent resources through the {@link oajr.annotation.Rest#children() @Rest(children)} annotation.

Example:

| /** Parent Resource */ | @Rest( | path="/parent", | children={MyChildResource.class} | ) | public MyRootResources extends BasicRestServletGroup {...}

| /** Child Resource */ | @Rest( | path="/child" // Path relative to parent resource. | ) | // Note that we don't need to extend from RestServlet. | public MyChildResource extends BasicRestObject {...}

The path of the child resource gets appended to the path of the parent resource. So in the example above, the child resource is accessed through the URL /parent/child.

One advantage of using child resources is that they do not need to be declared in the JEE web.xml file. Initialization of and access to the child resources occurs through the parent resource. Children can be nested arbitrary deep to create complex REST interfaces with a single top-level REST servlet.

As explained earlier, child REST objects typically extend from {@link oajr.servlet.BasicRestObject} or {@link oajr.servlet.BasicRestObjectGroup} and not from one of the servlet classes. They also technically don't even need to extend from those classes and can instead just be a normal class annotated with the bare-minimum {@link oajr.annotation.Rest @Rest} and {@link oajr.annotation.RestOp @RestOp} annotations.