Skip to content

This project provides a simple Dockerized RDF endpoint that serves an .rdf file and publish a SPARQL endpoint.

License

Notifications You must be signed in to change notification settings

mjanez/easy-rdf-endpoint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2c25300 · Mar 4, 2025

History

17 Commits
Feb 24, 2025
Feb 18, 2025
Feb 24, 2025
Feb 24, 2025
Feb 24, 2025
Feb 24, 2025
Feb 18, 2025
Feb 24, 2025
Mar 4, 2025
Feb 24, 2025
Feb 24, 2025
Mar 4, 2025

Repository files navigation

easy-rdf-endpoint - Use Docker to deploy and use a RDF Catalog

Overview

This project provides a simple Dockerized RDF endpoint that serves an .rdf file an provides an SPARQL Endpoint based on vemonet/rdflib-endpoint

  • SPARQL Features:

    • Integrated YASGUI editor with multi-tab support
    • Pre-configured example queries
    • Machine-readable SPARQL endpoint
  • Easy Deployment:

    • Docker and Kubernetes ready
    • Environment-based configuration
  • Security & Performance:

    • NGINX reverse proxy
    • SSL/TLS support
    • Configurable CORS
  • RDF Catalog Serving:

    • Serves Catalog .rdf files with proper Content-Type: application/rdf+xml
    • Compatible with DCAT-AP federators and RDF parsers

Landing Page SPARQL Editor

Quick Start

Use Codespaces to test easy-rdf-endpoint in your browser

GitHub Codespaces

Getting started

Requirements:

Clone and configure

Before starting the deployment, you'll need to set up a .env file. This file is crucial as it contains environment variables that the application needs to run properly.

  1. Clone project

    cd /path/to/my/project
    git clone https://github.com/mjanez/easy-rdf-endpoint.git & cd easy-rdf-endpoint
  2. Push your RDF catalog in folder: ./data

  3. Copy the .env.example template and modify the resulting .env to suit your needs.

    cp .env.example .env

    Adjust the vars as necessary, example the server name if not use localhost:

    # Server Configuration
    PROXY_SERVER_NAME=my-example-sparql-server.org
    
    # RDF of filename in folder ./data 
    CATALOG_FILE=my-custom-catalog.rdf
    
    # Edit your custom SPARQL queries that load as tabs at startup
    EXAMPLE_SPARQL_QUERIES='{
        "HVD info": {
            "query": "prefix dct: <http://purl.org/dc/terms/>\nprefix dcatap: <http://data.europa.eu/r5r/>\nprefix dcat: <http://www.w3.org/ns/dcat#>\n\nselect distinct ?title ?hvdCategory ?applicableLegislation ?accessService ?accessURL ?license\nwhere {\n  ?catalogo ?cp ?d.\n\n    # Dataset y su categoría HVD\n    ?d dcatap:applicableLegislation <http://data.europa.eu/eli/reg_impl/2023/138/oj>.\n    ?d a dcat:Dataset.\n    optional { ?d dcatap:hvdCategory ?hvdCategory. }\n    \n    # Distribution and its props\n    ?d dcat:distribution ?dist.\n    ?dist dcatap:applicableLegislation <http://data.europa.eu/eli/reg_impl/2023/138/oj>.\n    \n    optional { \n        ?dist dct:title ?title.\n        FILTER(langMatches(lang(?title), \"en\"))\n    } \n    optional { ?dist dcatap:applicableLegislation ?applicableLegislation. } \n    optional { ?dist dcat:accessURL ?accessURL. } \n    optional { ?dist dcat:accessService ?accessService. } \n    optional { ?dist dct:license ?license. } \n}\nORDER BY ?dist"
        },
        "Count stats": {
            "query": "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX dcat: <http://www.w3.org/ns/dcat#>\nPREFIX dct: <http://purl.org/dc/terms/>\n\nSELECT \n  (COUNT(DISTINCT ?dataset) AS ?totalDatasets)\n  (COUNT(DISTINCT ?distribution) AS ?totalDistributions)\n  (COUNT(DISTINCT ?dataservice) AS ?totalDataservices)\n  (COUNT(DISTINCT ?publisher) AS ?totalPublishers)\nWHERE {\n  {\n    ?dataset a dcat:Dataset .\n    OPTIONAL { ?dataset dct:publisher ?publisher }\n    OPTIONAL { ?dataset dcat:distribution ?distribution }\n  }\n  UNION\n  {\n    ?dataservice a dcat:DataService ;\n                 dcat:servesDataset ?dataset .\n  }\n}"
        },
        "Query types": {
            "query": "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX dct: <http://purl.org/dc/terms/>\nSELECT DISTINCT ?type ?label (COUNT(?s) as ?count) ?comment WHERE {\n    ?s rdf:type ?type .\n    OPTIONAL { ?type rdfs:label ?label }\n    OPTIONAL { ?type rdfs:comment ?comment }\n} \nGROUP BY ?type ?label ?comment\nORDER BY DESC(?count)\nLIMIT 10"
        }
    }' 
  4. Build & up the container.

docker compose up -d

Then, access your RDF file an endpoints.


Endpoints

The endpoints will be available at:

Project Structure

/easy-rdf-endpoint
│── /data/catalog.rdf          # Your Catalog RDF file (replace with your own)
│── /doc/                      # References, as images or documents, used in repo
│── /easy-rdf-endpoint/        # RDF+SPARQL Endpoint setup
│── /nginx/                    # NGINX docker setup
│── /src/                      # Now using NGINX instead of the old RDF serving mode
│── .env.example               # Sample ENVVars file for use with Docker Compose
│── docker-compose.yml         # Docker Compose config
│── README.md                  # Documentation

Tip

  • Replace catalog.rdf with your actual RDF file.
  • Works with Codespaces, Docker, Kubernetes, and any containerized environment.

Update SSL Certificate

To update the local SSL certificate, follow these steps:

  1. Generate a new certificate and private key:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout nginx/setup/easy-rdf-endpoint_local.key \
  -out nginx/setup/easy-rdf-endpoint_local.crt \
  -subj "/C=ES/ST=Madrid/L=Madrid/O=Development/CN=localhost"
  1. Verify that the files have been created correctly:
ls -l nginx/setup/easy-rdf-endpoint_local.*
  1. Restart the nginx container to apply the changes:
docker compose restart nginx

Caution

This certificate is for local development only. In production, use a valid certificate from a certificate authority.

Development

Using DevContainers

This project supports development using DevContainers, which provides a consistent development environment for all contributors.

Requirements:

Getting Started with DevContainer

  1. Clone the repository:
git clone https://github.com/mjanez/easy-rdf-endpoint.git
cd easy-rdf-endpoint
  1. Open in VS Code:
code .
  1. When prompted "Reopen in Container", click "Reopen in Container". Alternatively:
    • Press F1
    • Type "Remote-Containers: Reopen in Container"
    • Press Enter

VS Code will build and start the development container. This may take a few minutes the first time.

What's Included

The development container includes:

  • Python 3.11 environment
  • Required Python packages pre-installed
  • Popular VS Code extensions for Python/Docker development
  • Git configuration
  • Port forwarding for the application

Working in the Container

Once inside the container you can:

Image Credits

Some icons used in this project are from:

License

This work is a developed inspired by rdflib-endpoint by Vincent Emonet, licensed under MIT License.

This derivative work is licensed under Creative Commons Attribution 4.0 International License.

CC BY 4.0