Hello World Example
A REST resource is simply a Java class annotated with {@link oajr.annotation.RestResource}.
The most common case is a class that extends {@link oajr.RestServlet}, which itself is simply an
extension of {@link javax.servlet.http.HttpServlet} which allows it to be deployed as a servlet.
In this example, we define a resource called
This example is located in the
It's assumed the reader is familiar with defining servlets in web applications.
Like any servlet, we could define our resource in the
Our servlet code is shown below:
This is what it looks like in a browser:
http://localhost:10000/helloWorld
It doesn't much simpler than that.
In this case, we're simply returning a string that will be converted to any of the supported languages (e.g.
JSON, XML, HTML, ...).
However, we could have returned any POJO consisting of beans, maps, collections, etc...
The {@link oajr.BasicRestServlet} class that we're using here is a subclass of
{@link oajr.RestServlet} that provides default support for a variety of content types.
Implementers can choose to use this class, or create their own subclass of
{@link oajr.RestServlet} with their own specialized serializers and parsers.