What is Restagraph (Wikipages)

Restagraph - what is it?

Restagraph is an application that dynamically generates an HTTP API in front of a Neo4j graph database, based on a schema defined inside that database. The auto-generated API is regular and consistent, making it easy to build automation and GUIs on top of it.

This includes features such as:

Thus, it gives you relational-like schema and constraints, but with the flexibility that only a graph database can provide.

Benefits, a.k.a. the point of this thing

What does it look like?

Screenshots don't help much, because it's an HTTP API, so here's a quick demo of the very heart of it:

Create a JSON file with the following contents:

{
  "name": "Movies",
  "resourcetypes": [
    { "name": "Movie" }
  ],
  "relationships": [
    {
      "name": "ACTED_IN",
      "source-types": ["People"],
      "target-types": ["Movies"],
      "cardinality": "many:many"
    }
  ]
}

This defines a resourcetype called Movie, and a relationship from People to Movie (and only in that direction) called ACTED_IN. For this relationship, any number of people can be recorded to have acted in a movie, and a person can have acted in many movies. You don't need to define the "People" resourcetype, because that's predefined in Restagraph.

Upload that file to the server, via a command like this:

curl -X POST --data-urlencode schema@core_demo.json http://192.0.2.1:4950/schema/v1

Now create a person and a movie, and link them:

curl -X POST -d 'uid=Keanu Reeves' http://192.0.2.1:4950/raw/v1/People
curl -X POST -d 'uid=The Matrix' http://192.0.2.1:4950/raw/v1/Movie
curl -X POST -d 'target=/Movie/The_Matrix' http://192.0.2.1:4950/raw/v1/People/Keanu_Reeves/ACTED_IN

Ask the server what movies Keanu has acted in:

curl -s http://192.0.2.1:4950/raw/v1/People/Keanu_Reeves/ACTED_IN
[{"type":"Movie","uid":"The_Matrix","createddate":3851927697}]

For full detail about what it's capable of, read the HTTP API docs; for a detailed walkthrough of how to use it with the Neo4j movies dataset, read the demo session.

Where to get it

Source code is in Equill/restagraph on Codeberg.

Docker images are on Docker hub.

License

AGPL 3.0

You're free to use it, and you're free to build on it. If you extend the code itself, I expect you to share your changes.

Quick start

See the installation HOWTO.

The schema - how it works

Short version

The schema is stored in the database. Restagraph checks for it on startup; if one is present, it loads that into memory. If it doesn't find one, it installs the default (core) schema, then an additional schema if one is included, and loads the result into memory.

The additional schema is defined in a JSON file; you can upload any number of them via a separate API, and in fact this is the process for updating/upgrading a built-in one.

The core schema contains the essential resources and relationships on which the API itself relies, hence the name.

Elements of the schema

Resource-types

The types of things you can create via the API. If you're familiar with Object-Oriented Programming, resourcetypes correspond to classes and resources equate to instances.

The UID is a required attribute for all resourcetypes; you can't create a resource without one, so it isn't explicitly mentioned in the schema.

Attributes built into every resourcetype:

User-defined resource attributes

Resourcetypes can have any number of user-defined attributes. Each of these is defined with three main characteristics:

Relationships between resource-types

These define the relationships that the API will allow you to create from one resourcetype to another. Note that they're directional.

Mandatory attributes, which must be specified when defining one of these:

Optional attributes:

Important note: The any resourcetype can be used to define relationships from "any" other resourcetype to this one, or from this one to "any" other. So it's important to remember that when you query the Schema API about a resourcetype, the relationships section combines outbound relationships from "any" with those from the specific type you're querying it about. The same applies when it's validating a request to create a relationship.

That's the any resourcetype's reason for existence; the server won't allow you to create an instance, or to query one; it's only there to make relationship definitions manageable.

It's possible to define any-to-any relationships. There are genuine cases where it makes sense, but over-use of it defeats the point of having meaningful relationships.

The API

That is, how you actually put data into the system, and get it back out again.

That is, instances of a resourcetype. Their attributes are:

Relationships between resources

The simplest of the lot, because they have no user-serviceable attributes inside.

Created via POST, as long as they meet the constraints defined in the schema at that moment in time.

Test suite

Two test suites are included: - Client-side python tests, using pytest. - Internal tests of the implementation itself.

More information

There's more in the docs folder in this repo: