Principles

Principles are from wikipedia

REST's proponents argue that the web has enjoyed the scalability and growth that it has as a result of a few key design principles:

  • A stateless client/server protocol: each HTTP message contains all the information necessary to understand the request. As a result, neither the client nor the server needs to remember any communication-state between messages. In practice, however, many HTTP-based applications use cookies and other devices to maintain session state (some of those practices, like URL-rewriting, are not RESTful).
  • A set of well-defined operations that apply to all pieces of information (called resources): HTTP itself defines a small set of operations, the most important of which are GET, POST, PUT, and DELETE.
  • A universal syntax for resource-identification: in a RESTful system, every resource is uniquely addressable through the resource's URL (attempts to define a higher level of abstraction, the URI, have met little success, though the name "URI" will often appear in specifications and other literature).
  • The use of hypermedia both for application information and application state-transitions: representations in a REST system are typically HTML or XML files that contain both information and links to other resources; as a result, it is often possible to navigate from one REST resource to many others, simply by following links, without requiring the use of registries or other additional infrastructure.

Crispy REST guide

The special on the REST (REpresentational State Transfer) implementation is, that the invocation can you do about the URL. A example can you see on the picture.

REST example

In this simple example you can see a call from the echo-method with the parameter 'Hello Crispy!'. This a very easy way to test the server.

Parts from the URL are:

http://localhost:8092/crispy/rest?method=service.echo.echo&param0=Hello Crispy!

URL description
http://localhost:8092/ The URL and port from the server.
crispy The web context.
rest The servlet mapping string.
method Mapping string for the server to find a service object and method.
param0 Parameter for the service method.

Second possibile way to make a call with the URL:

http://localhost:8092/crispy/rest?class=test.crispy.example.service.Echo
			&method=echo&param0=Hello Crispy!

URL description
http://localhost:8092/ The URL and port from the server.
crispy The web context.
rest The servlet mapping string.
class The name of register service class.
method The service method.
param0 Parameter for the service method.

REST invocation with Crispy

  1. A very simple Crispy REST example:
  2. 	
    Properties prop = new Properties();
    prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8092/crispy/rest");
    prop.put(Property.EXECUTOR_CLASS, RestExecutor.class.getName());
    
    ServiceManager manager = new ServiceManager(prop);
    Echo echo = (Echo) manager.createService(Echo.class);
    		
  3. A complexes Crispy REST example with stop watch (test the performance):
  4. 	
    Properties prop = new Properties();
    prop.put(Property.INTERCEPTOR_CLASS, StopWatchInterceptor.class.getName());
    prop.put(Property.REMOTE_URL_AND_PORT, "http://localhost:8092/crispy/rest");
    prop.put(Property.EXECUTOR_CLASS, RestExecutor.class.getName());
    
    ServiceManager manager = new ServiceManager(prop);
    Echo echo = (Echo) manager.createService(Echo.class);
    System.out.println("Echo: " + echo.echo("Hello echo ..."));
    StopWatchInterceptor stopWatch = (StopWatchInterceptor) manager.getInterceptorByPos(0);
    System.out.println("StopWatch-newInstance: " + stopWatch.getStopTimeNewInstance());
    System.out.println("StopWatch-call: " + stopWatch.getStopTimeInvokeMethod() + "\n");
    		

Start the mini server:

MiniServer server = new MiniRestServer();
try {
	server.addService("test.crispy.example.service.Echo", "test.crispy.example.service.EchoImpl");
	server.addService("service.echo", "test.crispy.example.service.EchoImpl");
	server.addService("test.crispy.example.service.Calculator", "test.crispy.example.service.CalculatorImpl");
	server.addService("service.calculator", "test.crispy.example.service.CalculatorImpl");

	server.start();
			
	// all calls

} catch (Exception e) {
	e.printStackTrace();
}
finally {
	server.stop();
}		
		

Problems with Crispy REST

Not supported REST Datatypes:

  • Array's -> change Array's with java.util.Vector