Accessing API Endpoint
Access your Stardog instance’s REST API endpoint.
Page Contents
In addition to using the Stardog Applications, you can access your Stardog instance via its REST API endpoint directly at:
https://[custom-name].stardog.cloud:5820
You can find the custom-name
of your endpoint by going to cloud.stardog.com/connections and looking under Endpoint URL.
Access to the API endpoint is done via HTTP basic authentication over SSL. The API endpoint can be accessed via the administrative CLI tool stardog-admin
and data access CLI tool stardog
. For complete reference documentation on these tools, refer to the Stardog Admin CLI Reference and Stardog CLI Reference. Once you have the CLI installed, you can use it to manage your Stardog instance.
From there, create a user whose sole purpose is API access, and then connect to your API via that user.
Installing Stardog with CLI tools
To interact with Stardog via the CLI, you need to install Stardog on your local machine. For full instructions on installing Stardog on your preferred operating system, see Install Stardog.
You can verify Stardog is installed correctly by running a simple CLI command like so:
$ stardog-admin --server https://[custom-name].stardog.cloud:5820 -u <admin-user> db list
Best practices for API access users
The following are our recommendations for creating a user to access Stardog with an API:
- The admin user should create a user in their Stardog instance specifically for API access.
- This dedicated user should be distinct from other users.
- This user should be granted the fewest privileges required to perform its tasks.
To see more about creating users, see Managing Users and Roles.
Access Stardog with an API
You can find the full list of Stardog’s APIs at Programming with Stardog. Click on your preferred language and follow the instructions to install the API. When you are connecting to your Stardog endpoint with your code, you will use the credentials of the user you created in the previous step.
Here is a quick example using Starodg’s JavaScript library, stardog.js:
const { Connection, query } = require('stardog');
const conn = new Connection({
username: 'username_you_defined_earlier',
password: 'password_you_defined_earlier',
endpoint: 'https://[custom-name].stardog.cloud:5820',
});
// insert the rest of your code here