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

REST Web Service with Custom Media Types

This topic describes custom media types and explains how to use them. The example presented in this section further develops the example presented in Simple REST Web Service for an EJB Interface.

Media types are specified in the Accept and Content-Type header fields to specify the type of content supported by the application. For more information about the registered media types refer to: http://www.iana.org/assignments/media-types/.

The Junos Space platform uses custom media types for all platform provided functionality. The semantics for defining a custom Media Type are:

application/<vendor>.<app-name>.<service>.<type>+<syntax>: version=<version>

Where:

The following REST interface provides one custom Media Type (vnd.net.juniper.space.user-management.users) having multiple JSON and XML representations. Root level URI ???

@Path("/user-management")  // Root level URI for the service.
public interface JSUserMgmtSvc {
   @Path("/users")
   @GET
   // Custom media types with JSON subtype
   @Consumes("application/vnd.net.juniper.space.user-management.users+json")
   @Produces("application/vnd.net.juniper.space.user-management.users+json")
   public Collection<UserTO> getAllUsersForJSON();

   @Path("/users")
   @GET
   // Custom media types with XML subtype
   @Consumes("application/vnd.net.juniper.space.user-management.users+xml")
   @Produces("application/vnd.net.juniper.space.user-management.users+xml")
   public Collection<UserTO> getAllUsersForXML();
}

public JSUserMgmtSvcImpl implements JSUserMgmtSvc {
   public Collection<UserTO> getAllUsersForJSON() {
     // Look up EJB
     // Invoke EJB API to get all the Users.
     return;
   }
   public Collection<UserTO> getAllUsersForXML() {
     // Look up EJB
     // Invoke EJB API to get all the Users.
     return;
   }
}