Skip to content

Commit 457232c

Browse files
committed
Added information about the CLI Query interface, and http with curl
1 parent 0c3de90 commit 457232c

File tree

3 files changed

+211
-1
lines changed

3 files changed

+211
-1
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: How to use the HTTP Documents API
3+
nextjs:
4+
metadata:
5+
title: How to use the HTTP Documents API
6+
description: Quick introduction to the HTTP Documents API and how to use common ways to interact with it using various clients as a quick reference guide
7+
openGraph:
8+
images: https://assets.terminusdb.com/docs/technical-documentation-terminuscms-og.png
9+
alternates:
10+
canonical: https://terminusdb.org/docs/http-documents-api/
11+
media: []
12+
---
13+
14+
TerminusDB exposes a REST API for documents, a WOQL query interface with a datalog interface to the database and a GraphQL API, and several endpoints described in the [TerminusDB OpenAPI specification](/docs/openapi/).
15+
16+
The purpose of this guide is to show how to connect with both cloud and local TerminusDB instances. This is a simple way to interact with the database, without using the client libraries.
17+
18+
There are two main ways to authenticate with TerminusDB:
19+
20+
1. API token (for cloud instances)
21+
2. Basic authentication (when connecting to a local TerminusDB instance, such as in [Docker](/docs/install-terminusdb-as-a-docker-container/))
22+
23+
## Localhost TerminusDB
24+
25+
Here is a tutorial to connect to TerminusDB in docker or on localhost.
26+
27+
### Updating a document on localhost
28+
29+
* Instance name: admin
30+
* Data Product name: PeopleReferenceData
31+
* Graph: schema
32+
* Branch name: main
33+
* Schema document: Role
34+
* User: admin
35+
* Password: password
36+
* Provider: localhost:6363
37+
38+
```bash
39+
BASE64="$(echo -n 'admin:password' | base64)"
40+
DOC='{"@type":"Class","@id":"Role", "name":"xsd:string"}'
41+
curl -X POST -H 'Content-Type: application/json' -d "$DOC" -H "Authorization: Basic $BASE64" \
42+
"http://localhost:6363/api/document/admin/PeopleReferenceData/local/branch/[email protected]&message=InsertedDocument&graph_type=schema"
43+
```
44+
45+
If you already have the schema element and want to update it, use the `PUT` keyword.
46+
47+
### Creating a document on localhost
48+
49+
* Instance name: admin
50+
* Data Product name: PeopleReferenceData
51+
* Branch name: main
52+
* Document type: Role
53+
* Document id: Role/ContentProducer
54+
* User: admin
55+
* Password: password
56+
* Provider: localhost:6363
57+
58+
```bash
59+
BASE64="$(echo -n 'admin:password' | base64)"
60+
DOC='{"@type":"Role","@id":"Role/ContentProducer","name":"ContentProducer"}'
61+
curl -X POST -H 'Content-Type: application/json' -d "$DOC" -H "Authorization: Basic $BASE64" \
62+
"http://localhost:6363/api/document/admin/PeopleReferenceData/local/branch/[email protected]&message=InsertedDocument"
63+
```
64+
65+
### Deleting a document on localhost
66+
67+
```bash
68+
BASE64="$(echo -n 'admin:password' | base64)"
69+
DOCS='["Role/ContentProducer"]'
70+
curl -X DELETE -H 'Content-Type: application/json' -d "$DOCS" -H "Authorization: Basic $BASE64" \
71+
"http://localhost:6363/api/document/admin/PeopleReferenceData/local/branch/[email protected]&message=DeletedDocument"
72+
```
73+
74+
## Cloud TerminusDB
75+
76+
To connect to a cloud TerminusDB instance, such as with [DFRNT](https://dfrnt.com/hypergraph-content-studio), you need to mint an API token to your instance to get access to your data products, and documents stored in the branches of the data product.
77+
78+
To connect to a cloud environment, we will assume you are connecting to the DFRNT TerminusDB cloud.
79+
80+
### How to connect to cloud
81+
82+
Below is how to use an API token to connect to a cloud TerminusDB instance at DFRNT. Note that there is a two-part to the api endpoints:
83+
84+
1. api/hosted (can also be /api/dfrnt for instances connected via other API tokens)
85+
2. 000000000000-0000-0000-0000-00000001 (instance name)
86+
87+
Then, instead of the `admin` organization, you will have a team that you connect to, which is a guid unless you have a team plan and share an instance.
88+
89+
### Fetching a document (on a cloud instance with an API token)
90+
91+
Example of how to fetch information about the ContentProducer Role in TerminusDB. The location of the document:
92+
93+
* Instance name: 000000000000-0000-0000-0000-00000001 (it should be put twice)
94+
* Data Product name: PeopleReferenceData
95+
* Branch name: main
96+
* Document type: Role
97+
* Document id: Role/ContentProducer
98+
* Token: 000000000000-0000-0000-0000-00000001-000000000000-0000-0000-0000-00000001
99+
* Provider: https://dfrnt.com
100+
101+
```bash
102+
API_TOKEN="000000000000-0000-0000-0000-00000001-000000000000-0000-0000-0000-00000001"
103+
curl -X GET -H "Authorization: Token $API_TOKEN" \
104+
https://dfrnt.com/api/hosted/000000000000-0000-0000-0000-00000001/api/document/000000000000-0000-0000-0000-00000001/PeopleReferenceData/local/branch/main?id=Role/ContentProducer
105+
```
106+
107+
For more information about connecting to cloud instances, read [how to connect to the DFRNT API](https://support.dfrnt.com/portal/en/kb/articles/api).
108+
109+
110+
111+
112+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: How to use the terminusdb CLI query interface
3+
nextjs:
4+
metadata:
5+
title: How to use the terminusdb CLI query interface
6+
description: Quick introduction to the terminusdb CLI WOQL Query interface which has a distinct syntax to other flavours.
7+
openGraph:
8+
images: https://assets.terminusdb.com/docs/technical-documentation-terminuscms-og.png
9+
alternates:
10+
canonical: https://terminusdb.org/docs/terminusdb-db-cli-querying/
11+
media: []
12+
---
13+
14+
This is a tutorial to learn the command line CLI interface to start exploring the local TerminusDB _system database. Be careful in not making incorrect or uncontrolled changes to the _system database as it can lock you out of your data products.
15+
16+
*Disclaimer*: Do not run this tutorial with data that you do care about. Here be dragons. You have hereby been warned!
17+
18+
The local TerminusDB database CLI has a WOQL query interface built in, with a distinct syntax to other flavours. When working with a local TerminusDB instance, it is often handy to perform offline commands against it, or extract information in a data pipeline for ML/Ops.
19+
20+
This syntax is for advanced users who have significant experience with TerminusDB and WOQL. If you are new to TerminusDB, we recommend starting with the [TerminusDB Quickstart](/docs/get-started-with-terminusdb/).
21+
22+
## Syntax
23+
24+
The syntax of the WOQL query interface is distinct from other flavours, and is based more closely on the Prolog syntax. The WOQL logic is the same, but the syntax is different, especially for and, triple and other predicates expected in WOQL.
25+
26+
This documentation is incomplete and a stub. PRs are welcome to strengthen it and make it more complete. It only covers the syntax differences. Refer to the [WOQL Javascript syntax](/docs/javascript-woql/) as the main language interface.
27+
28+
We will use the system database as the example database for this guide as it's available on the local system.
29+
30+
### Getting started with a simple query
31+
32+
An example for finding the databases in the system:
33+
34+
```bash
35+
./terminusdb query _system "(
36+
t(Database,rdf:type,'@schema':'UserDatabase')
37+
)"
38+
```
39+
40+
A couple of notes:
41+
* All variables must start with a capital letter
42+
* The string values must be in single quotes
43+
* IRIs with prefixes must have the two portions quoted independently with a colon inbetween due to the `@` sign
44+
* the `triple` syntax is `t(A,B,C)` instead of `triple(A,B,C)`
45+
* the `quad` syntax is `t(A,B,C,schema)` instead of `quad(A,B,C,schema)`
46+
* the `and` syntax is `(statementA,statementB)` instead of `and(A,B)`
47+
* the `or` syntax is `(statementA;statementB)` instead of `or(A,B)`
48+
49+
### Finding which capabilities users have
50+
51+
The terminusdb client does not yet have the ability to find which capabilities a user has on which databases or organizations. This command queries them.
52+
53+
```bash
54+
./terminusdb query _system "select([User,Role,Scope],(
55+
t(Capability,rdf:type,'@schema':'Capability'),
56+
t(Capability,role,Role),
57+
t(Capability,scope,Scope),
58+
t(User,capability,Capability),
59+
User='User/[email protected]'
60+
))"
61+
```
62+
63+
Some additional notes:
64+
65+
* select works by binding variables to be returned
66+
* `t()` is used to bind triples
67+
* to bind a specific value, use bind variables to specific values using `=`
68+
* Note that the variables are unified by the values stored in the database
69+
70+
Or, to see the capabilities of all users, don't check for a specific user:
71+
72+
```bash
73+
./terminusdb query _system "select([User,Role,Scope],(
74+
t(Capability,rdf:type,'@schema':'Capability'),
75+
t(Capability,role,Role),
76+
t(Capability,scope,Scope),
77+
t(User,capability,Capability)
78+
))"
79+
```
80+
81+
### Graph Specifications, GRAPH_SPEC
82+
83+
To specify a graph to interact with, use the graph_spec before the query. Here are a couple of ways to specify a graph. The admin team is the default team on local TerminusDB instances.
84+
85+
* `_system`: the system database
86+
* `org/data_product`: main of a specific data product
87+
* `admin/data_product/local/branch/main` the main branch of the data product data_product in the admin organisation/team
88+
* `admin/data_product/local/commit/9w8hk3y6rb8tjdy961ed3i536ntkqd8` a specific commit in the data product data_product
89+

src/lib/navigation.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,13 @@ export const navigation: Navigation[] = [
170170
},
171171
],
172172
},
173-
174173
{
175174
title: 'Document Interface',
176175
links: [
176+
{
177+
title: 'HTTP Documents API',
178+
href: '/docs/http-documents-api',
179+
},
177180
{
178181
title: 'Document Graph Howto',
179182
href: '/docs/document-graph-api',
@@ -620,6 +623,12 @@ export const navigation: Navigation[] = [
620623
{
621624
title: 'TerminusDB CLI Reference',
622625
href: '/docs/terminusdb-cli-commands',
626+
links: [
627+
{
628+
title: 'TerminusDB CLI Querying',
629+
href: '/docs/terminusdb-db-cli-querying',
630+
},
631+
],
623632
},
624633
{
625634
title: 'Git-for-Data Reference',

0 commit comments

Comments
 (0)