-
Notifications
You must be signed in to change notification settings - Fork 0
HowToUseTheRPCDatabaseAPI
Tony Woode edited this page Apr 8, 2015
·
1 revision
Example:
Using CRUDL for "fact" objects
In the API definition, we have:
- This record definition:
record fact_entry (uri uri, int i, string subject, atom predicate, string object)
-
a module declaration for the "database" module,
-
and these call definitions within it:
method create_fact_entry (fact_entry f) -> (uri u) -- create a new fact entry in database
method get_fact_entry (uri u) -> (fact_entry f) -- get a specific fact entry from database
method update_fact_entry (uri u, fact_entry f) -> () -- update a specific fact entry in database
method delete_fact_entry (uri u) -> () -- delete a specific fact entry from database
method list_fact_entries () -> (LIST_OF fact_entry f) -- list all fact entries in database
So:
given this, the database interface automagically creates database access methods for each of these,
so you can do this:
(in Python, assuming you already have an implementation of the RPC-over-JSON-over-AMQP protocol)
headers = {
'message_type': 'rpc_request',
'method': 'create_fact_entry'
}
u = json_rpc.call('database', contentType='application/json', headers, {'subject': 's', 'predicate': 'p', 'object': 'o', 'i': 42})
headers = {
'message_type': 'rpc_request',
'method': 'update_fact_entry'
}
json_rpc.call('database', contentType='application/json', headers, {'u': u, 'changes': {'subject': 's', 'predicate': 'p', 'object': 'o', 'i': 54}})
headers = {
'message_type': 'rpc_request',
'method': 'get_fact_entry'
}
print json_rpc.call('database', contentType='application/json', headers, u)
list_headers = {
'message_type': 'rpc_request',
'method': 'list_fact_entries'
}
delete_headers = {
'message_type': 'rpc_request',
'method': 'delete_fact_entry'
}
for u in json_rpc.call('database', contentType='application/json', list_headers, None):
json_rpc.call('database', contentType='application/json', delete_headers, u)