# Quick Start: REST API v2 requests
#
# Use with the VS Code REST Client extension or the IntelliJ HTTP Client.
# The requests follow the order of the Quick Start guide, plus a few
# list and status calls.
#
# Change @host if the server is not running locally on port 8080. On Quine
# Enterprise, change @graph to target a graph other than the default `quine`;
# open source Quine has only the default graph.
#
# If authentication is enabled (Quine Enterprise with OIDC), add a line such as
#   Authorization: Bearer <access-token>
# directly below the request line of each request.

@host = http://127.0.0.1:8080
@graph = quine
@ingestName = wikipedia-page-create
@standingQueryName = wikipedia-new-page-node

### Create an ingest stream from the Wikipedia page-create event stream

POST {{host}}/api/v2/graph/{{graph}}/ingests
Content-Type: application/json

{
  "name": "{{ingestName}}",
  "source": {
    "type": "ServerSentEvent",
    "url": "https://stream.wikimedia.org/v2/stream/page-create",
    "format": {
      "type": "Json"
    }
  },
  "query": "CREATE ($that)"
}

### List ingest streams

GET {{host}}/api/v2/graph/{{graph}}/ingests

### Get the status of the ingest stream

GET {{host}}/api/v2/graph/{{graph}}/ingests/{{ingestName}}

### Return the most recently created node

POST {{host}}/api/v2/graph/{{graph}}/cypher:queryNodes
Content-Type: text/plain

CALL recentNodes(1)

### Create a standing query that prints the ID of each new node to the console

POST {{host}}/api/v2/graph/{{graph}}/standingQueries
Content-Type: application/json

{
  "name": "{{standingQueryName}}",
  "pattern": {
    "type": "Cypher",
    "query": "MATCH (n) RETURN DISTINCT id(n)"
  },
  "outputs": [
    {
      "name": "print-output",
      "destinations": [
        { "type": "StandardOut" }
      ]
    }
  ]
}

### List standing queries

GET {{host}}/api/v2/graph/{{graph}}/standingQueries

### Pause the ingest stream

POST {{host}}/api/v2/graph/{{graph}}/ingests/{{ingestName}}:pause

### Resume the ingest stream

POST {{host}}/api/v2/graph/{{graph}}/ingests/{{ingestName}}:resume

### Delete the standing query so that it does not run again after a restart

DELETE {{host}}/api/v2/graph/{{graph}}/standingQueries/{{standingQueryName}}

### Shut down Quine gracefully

POST {{host}}/api/v2/system:shutdown
