6.4. Rest API

6.4.1. Repository Rest API

The asset repository and any asset stored in the repository can be accessed via the Rest API. Assets can be accessed by package name or by category name.
The base http address to access the rest API is http://localhost:8080/jboss-brms/rest/, where localhost is replaced by the server name. If the default port has been changed, substitute the default 8080 port number for the new port number.

6.4.2. Accessing Rules by Package

Use the URLs listed below to access rules assets by package. The examples below assume a base URL of http://localhost:8080/jboss-brms/rest/.
The GET method produces MIME-Types:
  • application/atom+XML
  • application/json
  • application/xml
The GET method return all packages contained in the repository in the requested format (Atom feed, JSON, or XML).
The POST method produces MIME-Types:
  • application/atom+XML
  • application/json
  • application/xml
The POST method consumes MIME-Types:
  • application/octet-stream
  • application/atom+xml
  • application/json
  • application/xml
The POST method creates a new package from an input stream of DRL, an Atom feed, JSON, or XML, and returns the newly created package in the requested format (Atom feed, JSON, or XML).
The GET method produces MIME-Types:
  • application/atom+xml
  • application/json
  • application/xml
The GET method returns the metadata of the package {packageName} as an Atom entry when the MIME-Type is application/atom+xml and as a package element when the MIME-Type is application/json or application/xml.
The PUT method produces MIME-Types:
  • application/atom+xml
The PUT method updates the metadata of package {packageName} with the given Atom Entry.
The DELETE method deletes package {packageName}.
The GET method produces MIME-Types:
  • text/plain
The GET method returns the source code of the package {packageName} as a text file.
The GET method produces MIME-Types:
  • application/octet-stream
The GET method returns the compiled binary of the package {packageName} as a binary stream. If the package has not been compiled yet or its binary is not up to date, this will compile the package first.
The GET method produces MIME-Types:
  • application/atom+xml
The GET method returns the list of package {packageName} versions as an Atom Feed.
The GET method produces MIME-Types:
  • application/atom+xml
The GET method returns the metadata of package {packageName} and of version {version} as an Atom Entry.
The GET method produces MIME-Types:
  • text/plain
The GET method returns the source code of package {packageName} and of version {version} as a text file.
The GET method produces MIME-Types:
  • application/octet-stream
The GET method returns the binary (compiled code) of package {packageName} and of version {version} as an octet stream. If the package version has not been built, it returns HTTP code 500 with an error message.
The GET method produces MIME-Types:
  • application/atom+xml
  • application/json
  • application/xml
The GET method returns the list of rule assets contained in package {packageName} in the requested format (Atom feed, JSON, or XML).
The POST method produces MIME-Types:
  • application/atom+xml
  • application/octet-stream
The POST method creates an asset in package {packageName}.
When an Atom Entry is provided, the following information must be included in the input: asset name, asset description, asset initial category, and asset format.
When an octet-stream is provided, the value of slug header is used to indicate the name of the asset. If the slug header is missing, a HTTP 500 error is returned.
The GET method produces MIME-Types:
  • application/atom+xml
  • application/json
  • application/xml
The GET method returns the rule asset {assetName} contained in package {packageName} in the requested format (Atom feed, JSON, or XML).
The PUT method produces MIME-Types:
  • application/atom+xml
  • application/json
  • application/xml
The PUT method updates the metadata of the rule asset {assetName} contained in package {packageName} with the provided format (Atom Entry, JSON, or XML).
The DELETE method deletes the rule asset {assetName} contained in package {packageName}.
The GET method produces MIME-Types:
  • application/octet-stream
The GET method returns the binary content of rule asset {assetName} contained in package {packageName}. If this asset has no binary content, the source content is returned instead.
The PUT method produces MIME-Types:
  • application/octet-stream
The PUT method updates the binary content of the rule asset {assetName} contained in package {packageName}.
The GET method produces MIME-Types:
  • plain/text
The GET method returns the content of rule asset {assetName} contained in package {packageName}. If this is a binary asset, the binary data is returned as a byte array.
The PUT method produces MIME-Types:
  • plain/text
The PUT method updates the source code of the rule asset {assetName} contained in package {packageName}.
The GET method produces MIME-Types:
  • application/atom+xml
The GET method returns the list of rule asset {assetName} versions contained in package {packageName} as an Atom Feed.
The GET method produces MIME-Types:
  • application/atom+xml
The GET method returns the metadata of rule asset {assetName} of version {version} contained in package {packageName} as an Atom Entry.
/packages/{packageName}/assets/{assetName}/versions/{version}/source

http://localhost:8080/jboss-brms/rest/packages{packageName}/assets/{assetName}/versions/{version}/source

The GET method produces MIME-Types:
  • plain/text
The GET method returns the source code of rule asset {assetName} of version {version} contained in package {packageName} as a text file.
/packages/{packageName}/assets/{assetName}/versions/{version}/binary

http://localhost:8080/jboss-brms/rest/packages{packageName}/assets/{assetName}/versions/{version}/binary

The GET method produces MIME-Types:
  • application/octet-stream
The GET method returns the binary content of rule asset {assetName} of version {version} contained in package {packageName}. If this asset has no binary content, the source content is returned instead.

6.4.3. Accessing Rules by Category

Use the URLs listed below to access rules assets by category. The examples below assume a base URL of http://localhost:8080/jboss-brms/rest/
The GET method produces MIME-Types:
  • application/atom+xml
  • application/json
  • application/xml
The GET method returns an Atom feed or a list of objects that have the category {categoryName}.
The GET method produces MIME-Types:
  • application/json
  • application/xml
The GET method returns a list of asset objects representing rules assets that have the listed category {categoryPath} and retrieves page {page}, which is a numeric value starting at 1. A page contains 10 elements. If the list contains 20 elements then the list will have 2 pages. Page 1 must be called before page 2 and so on.

6.4.4. Source Code Examples

The following example uses apache CXF to show how to access the Rest API.

Example 6.1. Retrieving the source code for the web decision table

	WebClient client = WebClient.create("http://127.0.0.1:8080/");
	String content=client.path("jboss-brms/rest/packages/essaiRest/assets/tab2/source").accept("text/plain").get(String.class);
	GuidedDecisionTable52 dt = GuidedDTXMLPersistence.getInstance().unmarshal(content);
The first line of the example creates the a WebClient variable that points to the server.
The second line of the example retrieves the source code by accessing the /rest/packages/{packageName}/assets/{assetName}/source, where in our case packageName is "essaiRest" and assetName is "tab2".
The third line of the example transforms the string variable (the source code that contains the xml of the data structure of the web decision table) in the java structure (a java class) for web decision table GuidedDecisionTable52.

Example 6.2. Updating the source code of the web decision table

	String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode("guest:".getBytes());
	GuidedDecisionTable52 dt = new GuidedDecisionTable52();
	.. 
	Do some stuff here
	..
	String newContent = GuidedDTXMLPersistence.getInstance().marshal(dt);
	WebClient client2 = WebClient.create("http://127.0.0.1:8080/");
	client2.header("Authorization", authorizationHeader);
	Response response= client2.path("jboss-brms/rest/packages/essaiRest/assets/tab2/source").accept("application/xml").put(newContent);
The first line of the example creates a java String variable that contains the authorization element needed to update an asset in the asset repository.
The code that modifies the web decision table is not shown in this example.
The third line transforms the java structure into an XML structure that is put into a java String variable.
Next, the WebClient variable is created, but this time the authorization variable that contains the string from the first line (and contains the user name 'guest') is included in the header.
The final line adds the new content to the asset repository.