Using REST services to connect to other runtimes
The XPages NoSQL Database service supports the IBM® XPages for Bluemix™ runtime but it can also connect and work with other runtimes.
About this task
To connect an XPages NoSQL Database service instance to another runtime, you use the REST API provided by the XPages NoSQL Database service for storing and retrieving data. The first step in this process is to enable REST services access to your database. Follow these steps to do this:
Procedure
- Open the database in Domino® Designer.
For more information, see
Connecting to the XPages NoSQL Database service from Domino® Designer
found in the service documentation on the Bluemix™ site. - In the Applications Navigator, click Application Properties editor. to open the
- In the Application Properties editor, click the Advanced tab.
- In the Features section, select Views and documents from the Allow Domino Data Service menu.
- Click Save.
- To enable access for the View that you want to expose through the REST API, double-click the view in the Views section of the Applications Navigator.
- Right-click on the editor-pane and choose View
Properties from the menu.The View Properties dialog box appears.
- In the View Properties dialog box, click the Advanced tab.
- In the Web Access section, enable the Allow Domino Data Service operations option by clicking the check-box.
- Close the View Properties dialog and save the View. Repeat steps 6-10 for each View that you want to expose through the REST API.
Example
Now that you have enabled REST API access for you database,
you can use the REST API provided by the Service to parse the VCAP_SERVICES
environment
variable. The example that follows shows you how to retrieve view-specific
data that you might want to access via the other runtime.
The VCAP_SERVICES
environment
variable supplies the connection information and credentials to access
a bound XPages NoSQL Database service from any runtime. For example,
given the following VCAP_SERVICES environment variable:
{
"XPagesData": [
{
"name": "myXPagesDB-XPagesData",
"label": "XPagesData",
"plan": "xpages-data-free",
"credentials": {
"apppath": "bluemix/user/dev/data.nsf",
"username": "xxxxxx,
"host": "123.123.123.123",
"rootdir": "bluemix/user/dev/",
"servername": "CN=server_name/O=Bluemix",
"password": "xxxxxx",
}
}
]
}
With an application running in Bluemix, you can retrieve a View that is called "myview" from this database. To do this, send a GET request to https://123.123.123.123/bluemix/user/dev/data.nsf/api/data/collections/name/myview.
The
service responds with a 200 OK
response (the request
has succeeded) that contains the View entries in JSON format.
https://xpages-domino.ng.bluemix.net/bluemix/user/dev/data.nsf/api/data/collections/name/myview
.
To find the correct hostname to use for local testing, consult the
Bluemix Service Dashboard page where there is a value displayed called hostname (for
example, xpages-domino.ng.bluemix.net
).Providing security for REST requests
About this task
For security, all REST requests must be sent by HTTPS; HTTP is not enabled. You can require authentication by disabling anonymous access. When anonymous access is disabled, each REST request must contain a valid authorization header.
For credentials, use
the user name and password that is supplied by the VCAP_SERVICES
environment
variable. To disable anonymous access, modify the Access Control List
for the database with the following steps:
Procedure
- Open the database in Domino® Designer.
For more information, see
Connecting to the XPages NoSQL Database service from Domino® Designer
found in the service documentation on the Bluemix™ site. - In the Applications Navigator, right-click on the root of the application and select from the menu.
- The Access Control List dialog box
appears.This dialog controls which users can access the database and the access level of those users.
- If there is an Anonymous entry in
the list, select it and then select No Access from
the Access menu.If there is no Anonymous entry, no action is required.
- Select OK to save and close the dialog.