{8.0.0-updated} HelloWorldResource

The HelloWorldResource class is a simple resource that prints a "Hello world!" message.

HelloWorldResource.java

/** * Sample REST resource that prints out a simple "Hello world!" message. */ @Rest( title="Hello World", description="An example of the simplest-possible resource", path="/helloWorld", htmldoc=@HtmlDoc( aside={ "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", " <p>The POJO serialized is a simple String.</p>", "</div>" } ) ) public class HelloWorldResource implements BasicRestConfig { /** GET request handler */ @RestMethod(name=GET, path="/*", summary="Responds with \"Hello world!\"") public String sayHello() { return "Hello world!"; } }

Notice that in this case we're not extending from {@link oajr.RestServlet}. We are however implementing {@link oajr.BasicRestConfig} which is a no-op interface that defines a default @Rest annotation with all the serializers, parsers, and configuration defined on the {@link oajr.BasicRestServlet} class.

The only difference between implementing BasicRestConfig and extending from BasicRestServlet is that the latter provides the following additional features:

All other examples in this project extend from BasicRestServlet so that they provide automatic OPTIONS page support.

Pointing a browser to the resource shows the following:

http://localhost:10000/helloWorld

Using the special &Accept=text/json and &plainText=true parameters allows us to see this page rendered as JSON:

http://localhost:10000/helloWorld?Accept=text/json&plainText=true