/
Creating a REST API for CRUD SPARQL Templates using ENAPSO View Management Service

Creating a REST API for CRUD SPARQL Templates using ENAPSO View Management Service

This document outlines the process of creating a REST API to manage instances of a class using CRUD SPARQL Templates in the ENAPSO together View Management Service.

Prerequisites

Before creating a REST API, you must first define the necessary CRUD SPARQL Templates for managing instances of a class. You can follow the instructions on the following Confluence page to create these templates:

Creating CRUD SPARQL Templates

Once the templates are created, you can proceed with setting up the REST API.

Creating REST API Endpoints for SPARQL Templates

To create REST API endpoints for the defined SPARQL templates, send a request to the following endpoint:

POST /v1/create-endpoint-4-template

Request Payload Format

{ "records": [ { "endpoint": "domain", "baseURL": "/v1", "endpointConfig": [ { "method": "get", "template": "getListOfDomain" }, { "method": "post", "template": "createDomain" }, { "method": "put", "template": "updateDomain" }, { "method": "delete", "template": "deleteDomain" } ] } ] }

Request Parameters Explanation

  • records: An array of configuration objects that define a set of CRUD operations for a specific endpoint.

  • endpoint: The name of the REST endpoint.

  • baseURL: The base URL under which the endpoint is grouped (e.g., /v1).

  • endpointConfig: An array of objects specifying CRUD operations:

    • method: HTTP method (get, post, put, delete).

    • template: Name of the SPARQL template executed for this endpoint.

Expected Response

{ "status": 200, "message": "Route Created Successfully", "success": true, "records": [ {"success": true, "status": 200, "message": "Route GET /v1/domain created successfully."}, {"success": true, "status": 200, "message": "Route POST /v1/domain created successfully."}, {"success": true, "status": 200, "message": "Route PUT /v1/domain created successfully."}, {"success": true, "status": 200, "message": "Route DELETE /v1/domain created successfully."} ] }

Using the Created Endpoints

Once the endpoints are successfully created, you can send requests to them with the required variables.

Create an Instance (POST /v1/domain)

{ "variables": { "domainValues": [ {"domain": "Check New", "language": "en"}, {"domain": "Hallo New", "language": "de"} ] } }

2. Read Data (GET /v1/domain)

Send a GET request with query parameters:

GET /v1/domain?limit=1&offset=5&language=fr&calculateTotal=true&countPropertyName=?iri

Query Parameters:

  • limit: Specifies the number of records to return.

  • offset: Specifies the starting point for fetching records.

  • language: Specifies the language of the returned data (e.g., fr for French).

  • calculateTotal: Set to true to include the total number of records in the response (default: false).

  • countPropertyName: Defines the property based on which the count is calculated (default: *).

  • Any additional parameters can be passed in the format name=value, as demonstrated with language=fr.

3. Update an Instance (PUT /v1/domain)

{ "variables": { "domainIRI": "http://ont.enapso.com/companion/data#Domain_a06a7605-d374-47b1-b2bb-e4512df04cc7", "domainValues": [ {"domain": "Hell", "language": "en"}, {"domain": "Hollo", "language": "fr"} ] } }

4. Delete an Instance (DELETE /v1/domain)

{ "variables": { "domain": "Hell" } }

Conclusion

Following the steps above, you can successfully create and manage REST API endpoints for CRUD operations on SPARQL templates using the ENAPSO together View Management Service.

Related content

(C) Copyright 2014-2024 INNOTRADE GmbH, Herzogenrath, NRW, Germany (all rights reserved)