Graph and Query APIs
Learn how to define graph and query APIs for the graph service.
We'll cover the following...
Graph API
We can define our graph services API as follows:
Press + to interact
def graph_create(%GraphCommons.Graph{} = graph) doif rdf_store_admin() dograph_delete()graph_update(graph)else{:error, rdf_store()}endenddef graph_delete() doif rdf_store_admin() do{:ok, env} = Tesla.delete(rdf_store_admin())GraphCommons.Graph.new(env.body, "", :rdf)envelse{:error, rdf_store()}endenddef graph_read() doif rdf_store_admin() do{:ok, env} = Tesla.get(rdf_store_admin())GraphCommons.Graph.new(env.body, "", :rdf)else{:error, rdf_store()}endenddef graph_update(%GraphCommons.Graph{} = graph) doif rdf_store_admin() do{:ok, env} = Tesla.post(rdf_store_admin(), graph.data, headers: [{"content-type", "text/turtle"}])GraphCommons.Graph.new(env.body, "", :rdf)else{:error, rdf_store()}endend
This defines the API for CRUD operations, although we can expand the API further with the optional reporting function ...