Introduction
Dydra is a cloud-based RDF database service that provides a SPARQL endpoint and REST API. This article explains how to programmatically register RDF data using the Dydra API.
Prerequisites
- Dydra account
- API key
- Node.js environment (v16 or higher recommended, when using Node.js)
Note: The code examples in this article use the following as samples:
- Account name:
your-account - Repository name:
your-repository - API key:
your_api_key_here
When actually using these, replace them with your own Dydra account information.
API Basic Information
Endpoint Structure
Authentication
Dydra uses Bearer token authentication:
Implementation Methods
The Dydra API can be accessed using various methods including curl, Python, and Node.js. Each method is introduced below.
Method 1: curl Implementation (Simplest)
With curl, data registration is possible immediately without any programming language.
Basic Authentication
Registering Data in Turtle Format
Example data.ttl:
Registering Inline Data
Registering with SPARQL UPDATE
Executing SPARQL Queries
Deleting Data
Registering in JSON-LD Format
curl Script Example
A shell script for registering multiple files consecutively:
0
Checking Responses
1
Method 2: Python Implementation
2
Method 3: Node.js/TypeScript Implementation
Basic Setup
First, install the required packages:
3
Save the API key in an environment variable file (.env):
4
Dydra Client Class Implementation
5
Node.js Usage Examples
Basic Data Registration
6
Registration with SPARQL UPDATE
7
Searching Data
8
Comparison of Implementation Methods
| Method | Advantages | Disadvantages | Recommended Use |
|---|---|---|---|
| curl | No environment setup needed, immediate execution, automatable with shell scripts | Complex logic is difficult, weak error handling | Quick tests, simple batch processing, CI/CD pipelines |
| Python | Readable, rich libraries, integration with data analysis | Lower type safety | Data analysis, script processing, machine learning integration |
| Node.js/TS | Type safety, good async processing, Web API integration | Initial setup required | Web applications, large-scale systems, production environments |
Summary
By using the Dydra API, you can flexibly and programmatically manage RDF data.
Guidelines for Choosing an Implementation Method
Use curl (shell scripts) when:
- Quick testing and validation
- Automation in CI/CD pipelines
- Minimizing environment setup
- Simple batch processing
Use Python when:
- Integration with data analysis
- Integration with machine learning pipelines
- Complex data transformation processing
- Prototyping in Jupyter Notebooks
Use Node.js/TypeScript when:
- Web application development
- Type safety is important
- Large-scale systems
- Long-term production environment operation
Important Points
- API key management: Use environment variables, don’t hardcode in code
- Error handling: Retry logic and appropriate logging
- Rate limiting: Set appropriate delays between requests
- Validation: Check RDF syntax before data registration
- Batch processing: Split and process large volumes of data
Next Steps
- Check detailed specifications in the Dydra official documentation
- Learn queries from the SPARQL 1.1 specification
- Master RDF notation from the RDF Turtle specification
- Customize the code in this article to fit your use case
Use the patterns introduced in this article to build a robust RDF data management system.