{title:'Resource Classes', created:'8.0.0'}

This section describes how to define a top-level REST resource page and deploy it in our microservice. The example is a router page that serves as a jumping off page to child resources.

| @Rest( | path="/*", | title="My Microservice", | description="Top-level resources page", | htmldoc=@HtmlDoc( | navlinks={ | "options: servlet:/?method=OPTIONS" | } | ), | children={ | HelloWorldResource.class, | ConfigResource.class, | LogsResource.class | } | ) | public class RootResources extends BasicRestServletGroup { | // No code! | }

When deployed, it looks like this in a browser:

| http://localhost:10000

If you click the helloWorld link in your application, you'll get a simple hello world message:

| http://localhost:10000/helloWorld

...which is generated by this class...

| @Rest( | path="/helloWorld", | title="Hello World example", | description="Simplest possible REST resource" | ) | public class HelloWorldResource extends BasicRestServlet { | | @RestGet("/*") | public String sayHello() { | return "Hello world!"; | } | }

The most-common case for deploying the top-level resource is to use the {@link oaj.microservice.jetty.JettyMicroservice.Builder#servlet(Class)} method:

| public class App { | public static void main(String[] args) { | JettyMicroservice | .create() | .args(args) | .servlet(RootResources.class) // Our root resource. | .build() | .start() | ; | } | }

However, there are multiple ways of deploying top-level resources: