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:
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.
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¶m0=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¶m0=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. |
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);
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();
}