HTTP REST
Updated at:
This topic describes how to use RESTful HTTP requests to connect to and manage Graph Database (GDB) instances. RESTful APIs are compatible with Gremlin versions 3.3.x and 3.4.0.
Prerequisites
Ensure that your Graph Database (GDB) instance and your Elastic Compute Service (ECS) virtual machine are in the same Virtual Private Cloud (VPC).
Procedure
An example is provided in this topic. You must change the connection configurations in the example based on the information about your GDB instance.
- Replace the your-gdb-endpoint value in ${your-gdb-endpoint} with the endpoint of your GDB instance.
- Replace the username value in ${username} with the username of your GDB instance.
- Replace the password value in ${password} with the password of your GDB instance.
- The HTTP endpoint of your GDB instance is
${your_gdb_endpoint}:8182/gremlin. - You can use a GET or POST request to connect. We recommend that you use a POST request for operations:
curl -u ${username}:${password} -X POST -d '{"gremlin":"g.V().limit(1)"}' http://${your_gdb_endpoint}:8182/gremlin // Note: You need to escape the double quotes for the label value. curl -u ${username}:${password} -X POST -d '{"gremlin":"g.V().hasLabel(\"movie\").limit(10)"}' http://${your_gdb_endpoint}:8182/gremlin curl -u ${username}:${password} "http://${your_gdb_endpoint}:8182/gremlin?gremlin=g.V().limit(1)" - When you send a RESTful request to access the GDB server, you can add parameters using bindings:
curl -u ${username}:${password} -X POST -d '{"gremlin":"g.V().limit(n)","bindings":{"n":1}}' http://${your_gdb_endpoint}:8182/gremlin - The following result is returned in the example:
{ "requestId": "e640005a-f2fd-403e-812c-f61e7a3fb7cb", "result": { "data": { "@type": "g:List", "@value": [ { "@type": "g:Vertex", "@value": { "id": "3a63cc90-d957-4324-9ffc-16a8e4c1c1f4", "label": "label", "properties": { "pint": [ { "@type": "g:VertexProperty", "@value": { "id": "3a63cc90-d957-4324-9ffc-16a8e4c1c1f4", "label": "label", "value": { "@type": "g:Int32", "@value": 3 } } } ] } } } ] }, "meta": { "@type": "g:Map", "@value": [] } }, "status": { "attributes": { "@type": "g:Map", "@value": [] }, "code": 200, "message": "" } }
The preceding example uses g.V().limit(n) to traverse and return a subset of vertices from GDB. For more domain-specific language (DSL) examples, see Connect to an instance using the Gremlin console.
You can use templates to send RESTful API requests, as shown in the following example:
Use hard coding to specify your DSL command.
g.V().hasLabel('gdb_sample_person').drop()
|
|
V
Use a template to send your request.
g.V().hasLabel(label).drop()
bindings:{"label":"gdb_sample_person"}For more information about Gremlin RESTful APIs, see Connecting via HTTP in the Apache TinkerPop3 documentation.
Is this page helpful?