curl and
jq are used. However, the real intention
here is to show other programmers how they could implement a client in their
language on top of the HTTP API.
For an example of how to build a client on top of gRPC, refer to the
implementation of the Go client.
Similar to the Go client example, we use a bank account transfer example.
start_ts). This uniquely identifies a transaction, and
doesnβt change over the transaction lifecycle.
keys). This aids in
transaction conflict detection.
Every mutation would send back a new set of keys. The client must merge them
with the existing set. Optionally, a client can de-dup these keys while
merging.
preds). This aids in
predicate move detection.
Every mutation would send back a new set of predicates. The client must merge
them with the existing set. Optionally, a client can de-dup these keys while
merging.
/alter endpoint:
/query endpoint.
start_ts can
initially be set to 0. keys can start as an empty set.
For both query and mutation if the start_ts is provided as a path parameter,
then the operation is performed as part of the ongoing transaction. Otherwise, a
new transaction is initiated.
/query endpoint is used. Remember to set the
Content-Type header to application/dql to ensure that the body of the
request is parsed correctly.
To get the balances for both accounts:
data field is additional
data in the extensions -> txn field. This data has to be tracked by the
client.
For queries, there is a start_ts in the response. This start_ts needs to be
used in all subsequent interactions with Dgraph for this transaction, and so
should become part of the transaction state.
POST request to an Alphaβs
/mutate endpoint. We need to send a mutation to Dgraph with the updated
balances. If Bob transfers $10 to Alice, then the RDF triples to send are:
/mutate endpoint. We need to provide our
transaction start timestamp as a path parameter, so that Dgraph knows which
transaction the mutation should be part of. We also need to set Content-Type
header to application/rdf to specify that mutation is written in RDF format.
keys and predicates which should be added to the
transaction state.
/commit endpoint as explained in this section). To do
this, add the parameter commitNow in the URL /mutate?commitNow=true./commit endpoint. We need the
start_ts weβve been using for the transaction along with the list of keys
and the list of predicates. If we had performed multiple mutations in the
transaction instead of just one, then the keys and predicates provided during
the commit would be the union of all keys and predicates returned in the
responses from the /mutate endpoint.
The preds field is used to cancel the transaction in cases where some of the
predicates are moved. This field isnβt required and the /commit endpoint also
accepts the old format, which was a single array of keys.
/commit endpoint with the abort=true
parameter while specifying the startTs value for the transaction.
ro=true to /query to set it as a
read-only query.
/query,
/mutate, and /alter.
Compressed requests: to send compressed requests, set the HTTP request header
Content-Encoding: gzip along with the gzip-compressed payload.
Compressed responses: to receive compressed responses, set the HTTP request
header Accept-Encoding: gzip.
Example of a compressed request via curl:
--compressed option that automatically
requests for a compressed response (Accept-Encoding header) and decompresses
the compressed response.query and variables. The JSON format is required to set
GraphQL Variables with the HTTP API.
This query: