Junos Space SDK > Developer Guides > Junos Space Application Developer Guide > Programming with the Junos Space SDK > Developing Junos Space Applications > Creating REST Services

Simple REST Web Service for an EJB Interface

This page shows you how to write a REST Web service for an EJB interface. The following is a user management EJB application. It employs a single API to fetch all users from the database and consists of the EJB interface and its implementation. This EJB application has a corresponding REST interface and implementation for the EJB interface.

EJB Interface with API to Fetch All Users

The following is the EJB interface and its implementation. It includes an API to fetch all users.

public interface UserManagement {

/**
 * Gets the collection of Users
 * @return Collection : returns a collection of Users
 */
public Collection<UserTO> getAllUsers(); 

}

public class UserMgmtImpl implements UserManagement {

   /**
    * Description: This method returns a list of Users.
    * @return Collection : returns a collection of Users
    */
   public Collection getAllUsers() {

     // Fill up UserTO and return it.

     Collection col;
     return col;
   }
}

public class UserTO {

  private int id;
  private String name;
  private String lastName;
  private UserProfile profile;

  ......

  // Code for relevant get/set methods, constructor 
  // and UserProfile definition.

}

Standard REST interface for the EJB Interface

The following is the standard REST interface and REST implementation for the previous EJB.

@Path("/user-management")  // Root level URI for the service.

public interface JSUserMgmtSvc {

  @Path("/users")
  @GET
  @Consumes("application/json")
  @Produces("application/json")
  public Collection getAllUsers();
}

public JSUserMgmtSvcImpl implements JSUserMgmtSvc{

  public Collection getAllUsers() {

    // Code to look up EJB.
    // Code to invoke EJB API to get all Users.

    return;
  }

}