| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| Router Pages |
| |
| <p> |
| The {@link oajr.BasicRestServletGroup} class provides a default "router" page for |
| child resources when a parent resource is nothing more than a grouping of child resources. |
| </p> |
| <p> |
| The <l>RootResources</l> class in the Samples project is an example of a router page: |
| </p> |
| <p class='bpcode w800'> |
| <jd>/** |
| * Sample REST resource showing how to implement a "router" resource page. |
| */</jd> |
| <ja>@RestResource</ja>( |
| path=<js>"/"</js>, |
| title=<js>"Root resources"</js>, |
| description=<js>"Example of a router resource page."</js>, |
| children={ |
| HelloWorldResource.<jk>class</jk>, |
| PetStoreResource.<jk>class</jk>, |
| RequestEchoResource.<jk>class</jk>, |
| AddressBookResource.<jk>class</jk>, |
| SampleRrpcServlet.<jk>class</jk>, |
| PhotosResource.<jk>class</jk>, |
| DtoExamples.<jk>class</jk>, |
| SqlQueryResource.<jk>class</jk>, |
| ConfigResource.<jk>class</jk>, |
| LogsResource.<jk>class</jk>, |
| DebugResource.<jk>class</jk>, |
| ShutdownResource.<jk>class</jk> |
| } |
| ) |
| <jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletGroup { |
| <jc>// NO CODE!!!</jc> |
| } |
| </p> |
| <p> |
| When you bring up this resource in a browser, you see the following that provides a list |
| of navigable links to your child resources: |
| </p> |
| <p class='bpcode w800'> |
| http://localhost:10000 |
| </p> |
| <img class='bordered w800' src='doc-files/juneau-rest-server.RouterPages.1.png'/> |
| <p> |
| The {@link oajr.BasicRestServletGroup} class is nothing more than a subclass of |
| {@link oajr.BasicRestServlet} with a <l>getChildren()</l> method mapped to the servlet |
| root path. |
| <br>The method returns a POJO with is just a linked-list of beans with name/description properties. |
| </p> |
| <p class='bpcode w800'> |
| <jc>// The entire contents of the BasicRestServletGroup class.</jc> |
| |
| <jk>public class</jk> BasicRestServletGroup <jk>extends</jk> BasicRestServlet { |
| |
| <ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/"</js>, description=<js>"Child resources"</js>) |
| <jk>public</jk> ChildResourceDescriptions getChildren(RestRequest req) { |
| <jk>return new</jk> ChildResourceDescriptions(<jk>this</jk>, req); |
| } |
| } |
| </p> |