# Virtual graph from REST API

**URL:** <https://community.stardog.com/t/virtual-graph-from-rest-api/1399>\
**Category:** Support\
**Created:** [November 22, 2018, 8:41pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399 "2018-11-22T20:41:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![semanticfire](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/semanticfire/32/47_2.png) [@semanticfire](https://community.stardog.com/u/semanticfire)\
**Post date:** [November 22, 2018, 8:41pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/1 "2018-11-22T20:41:16Z")

</div>

Hi

This might be somewhat of a broad question to ask but I'll try it anyway,  
I would like to incorporate a REST API into a virtual graph, so results that come from a REST API converted to RDF and then in general queryable through SPARQL.

E.g. I have a set of data about buildings with ID's in my graphstore, I'd like to have the ID as a parameter to the REST Api and the result for example building details incorporated into the knowledge graph.

If the question is not clear let me know as well 🙂

Bart

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [November 23, 2018, 8:22pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/2 "2018-11-23T20:22:59Z")

</div>

Hi Bart,

Good question. 🙂 While the inbuilt virtual graph feature is targeted at mapping other databases, we do provide a semi-public service API. The service API provides an extension point which can be used to answer a fragment of a SPARQL query. The implementation must be written in Java (or another JVM language). We have an entry in the examples repo [here](https://github.com/stardog-union/stardog-examples/blob/develop/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java) with a [test](https://github.com/stardog-union/stardog-examples/blob/develop/examples/service/test/src/com/complexible/stardog/examples/service/TestExampleService.java#L104) that illustrates how to use it.

We recognize the importance of this type of integration and plan to offer a REST-based virtual graph facility in the future.

Jess

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [November 30, 2018, 3:28pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/3 "2018-11-30T15:28:32Z")

</div>

I've been a bit curious about one aspect of the service api. It doesn't appear to require that the service portion _must_ be a sparql fragment. If that's the case how terrible of a person would I be to put something other than a sparql fragment in there?

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [November 30, 2018, 3:31pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/4 "2018-11-30T15:31:06Z")

</div>

The "plan node" argument to `createQuery()` is a query fragment. What you do with that is up to you.

Jess

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [November 30, 2018, 3:41pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/5 "2018-11-30T15:41:59Z")

</div>

So the query will fail to parse if it's not a valid query fragment?

For example, could you do something like this...

```
SELECT * WHERE {
  SERVICE <jdbc:myql://localhost/test> {
          SELECT * FROM mytable
  }
}

```

It's just and example and I know that's something you could do with a virtual graph mapping.

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [November 30, 2018, 4:01pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/6 "2018-11-30T16:01:55Z")

</div>

Yeah that will fail to parse. However, there's nothing stopping you from putting `:my :query "SELECT * FROM mytable"` inside the service block.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 14, 2018, 4:01pm UTC](https://community.stardog.com/t/virtual-graph-from-rest-api/1399/7 "2018-12-14T16:01:57Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
