Knowledge Graph part-3 :Building REST API over Knowledge Graph

Nikita sharma
3 min readAug 24, 2019
Photo by Clint Adair on Unsplash

In our previous post, we discussed about getting started with knowledge graph where we saw how to install neo4j in Docker and Modelling tabular data as graph where we saw how we can push the data to our graphical database.

Now that we have all the data in our graph database, we can analyse it directly in Neo4j. However a lot of time we need to access small part of the data via apps and we would need to build an API layer on the graph DB and expose only the relevant information.

In this post, we will discuss about exposing our knowledge graph via Flask API. All the data will be exposed in JSON format.

Identifying the queries

First, we will decide what we want to expose in our API. Let’s come up with few hypothetical requirements :

  • Get a particular user’s details
  • Get user’s details and all connections for a given user
  • Size of our knowledge graph : count of all the nodes in our graph

Constructing Cypher queries

Now that we have decided what data we want to expose, we will write queries to fetch the data from Neo4j.

Get a particular user’s details