Standalone Restful service using Restlet framework

In this article, we will create a standalone Restful web service using Restlet framework and Maven.

If you need help setting up Maven, refer this article :
Maven basics
Let’s create a standalone java application by using the following archetype in command prompt:

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DartifactId=RestletStandAloneApp -DinteractiveMode=false

Open the project in eclipse or in any other IDE and add following dependency in it :

Also, add this repository :
      <name>Public online Restlet repository</name>

The project should automatically download the dependent jars. You can also force it using mvn compile.

Create Resource

In package, create following resource class :


import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class HelloWorldResource extends ServerResource {
  public String getMsg() {
    return "Hello World";


Create Server

We need to create a Http server connector to make this resource available.
Create a file in same package(unless already created by Maven) and add following code :


import org.restlet.Server;

 * Hello world!
public class App 
    public static void main( String[] args ) throws Exception
        System.out.println( "Hello World!" );
        // Use any available port
        Server helloServer = new Server(Protocol.HTTP, 8182,


Test the service

Run the java program and point your browser to :

You should see :

Hello World


Create Client

Restlet also lets us create client to consume a service.

ClientResource works as a proxy that we can use to run methods on the remote resource.



import org.restlet.resource.ClientResource;
import org.restlet.resource.ResourceException;

public class HelloWorldClient {

  public static void main(String[] args) throws ResourceException, IOException {
    ClientResource clientResource =
        new ClientResource("http://localhost:8182/");


Running this program should produce following output :

Hello World


Here is the structure of the project generated :
restlet standalone service


Code download from GitHub
You may also like following articles :

Restful webservice with Jersey and Grizzly

Restful webservice with Jersey

Restful webservice with CRUD operations using Jersey and Hibernate


© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

Leave a Reply.. code can be added in <code> </code> tags