Prerequisites
- TerminusDB running locally (install guide)
- A database with existing documents
What you'll achieve By the end of this guide, you will have retrieved documents from your TerminusDB database using the JavaScript client, the Python client, or the HTTP API.
Get a single document
Retrieve a document by its ID:
Example: TypeScript
const getDoc = async () => {
const doc = await client.getDocument({ id: "Player/Doug" })
console.log("Player/Doug:", doc)
}Returns:
Example: JSON
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
}Example: Python
document = client.get_document("Player/Doug")Returns:
Example: JSON
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
}curl -u admin:root \
"http://localhost:6363/api/document/admin/mydb/local/branch/main?id=Player/Doug"Returns:
Example: JSON
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
}Get all documents
Retrieve every document in the database:
Example: TypeScript
const getDocs = async () => {
const documents = await client.getDocument({ as_list: "true" })
console.log("All documents:", documents)
}Returns:
Example: JSON
[
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
},
{
"@id" : "Player/George",
"@type" : "Player",
"name" : "George",
"position": "Center Back"
},
{
"@id" : "Player/Karen",
"@type" : "Player",
"name" : "Karen",
"position": "Center Forward"
}
]Example: Python
documents = list(client.get_all_documents())get_all_documents returns a generator — wrap it with list() if you need to iterate more than once.
Example: JSON
[
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
},
{
"@id" : "Player/George",
"@type" : "Player",
"name" : "George",
"position": "Center Back"
},
{
"@id" : "Player/Karen",
"@type" : "Player",
"name" : "Karen",
"position": "Center Forward"
}
]curl -u admin:root \
"http://localhost:6363/api/document/admin/mydb/local/branch/main?as_list=true"Returns:
Example: JSON
[
{
"@id" : "Player/Doug",
"@type" : "Player",
"name" : "Doug",
"position": "Full Back"
},
{
"@id" : "Player/George",
"@type" : "Player",
"name" : "George",
"position": "Center Back"
},
{
"@id" : "Player/Karen",
"@type" : "Player",
"name" : "Karen",
"position": "Center Forward"
}
]Next steps
You've retrieved documents from TerminusDB. Next, you might want to:
- Edit documents — update the documents you just fetched
- Query with WOQL — use pattern-matching queries for complex filtering
- Delete documents — remove documents you no longer need