A Simple Example

Below is an example of what a typical REST resource would look like in your Platform module.

@Path("/test")
class TestResource extends BaseResource {
 
@GET
public JSONObject getSomething(@QueryParam("foo") String foo){
...
}
@POST
JSONObject postSomething(@FormParam("foo") JSONObject json){
...
}
@GET
@Path("/{id}")
JSONObject getSomethingElse(@PathParam("id") int id){
...
}
}
  • The class itself is annotated with @Path to indicate the base path for all of the methods of the resource, in this case its '/test'. This path is relative to the base REST path of your module which is "/oms/rest/MOD/" where MOD is your module prefix. That makes the full path of this resource "/oms/rest/MOD/test".

  • Each of the methods of this class is annotated with one of the HTTP methods: GET, POST, PUT or DELETE. Based on the method, you retrieve the parameters in a different way using different annotations. These are explained in more detail in the next section.

  • The last method is annotated with a Path too, which will be relative to the resource's path. In this case, the method will service GET requests for '/test/{id}' where '{id}' is a number that will be read as one of the arguments to the method.

REST resources are not transactional by default, but you can easily add annotations to indicate that some methods must commit completely or not at all. See the javadocs for com.onenetwork.platform.integ.rest.BaseResource for more information.