Making Drupal more RESTful with Akiban
Last week, I published an article on how to install Drupal 7 with Akiban as the backend database. Today, I wanted to briefly show off our REST API using the schema that is created with a standard install of Drupal 7 core.
First, I installed the devel module and generated some data since a bare bones install with no data would not be much fun. This server is running on a publically available EC2 instance too so if you are interested in trying these examples out yourself at home, feel free to do so! I’ll leave the EC2 instance up and running for the remainder of 2012 but if anyone wants to try the examples out and the instance seems unavailable, please let me know and I’ll fire it up again for you.
For the first few examples, I’m going to use curl
since its available on nearly every system (including OSX). Lets first get the version of the Akiban we are going to be interacting with:
<span class="gp">$</span> curl -X GET -H <span class="s2">"Content-Type: application/json"</span> http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/version<span class="go">[</span><span class="go">{"server_name":"Akiban Server","server_version":"1.4.4.2451"}</span><span class="go">]</span><span class="gp">$</span>
Lets continue this trend of a few simple examples to get started. I want to know the list of schemas on this server I am interacting with:
<span class="gp">$</span> curl -X GET -H <span class="s2">"Content-Type: application/json"</span> http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/information_schema.schemata<span class="go">[</span><span class="go">{"schema_name":"drupal","schema_owner":null,"default_character_set_name":null,"default_collation_name":null},</span><span class="go">{"schema_name":"information_schema","schema_owner":null,"default_character_set_name":null,"default_collation_name":null},</span><span class="go">{"schema_name":"sqlj","schema_owner":null,"default_character_set_name":null,"default_collation_name":null},</span><span class="go">{"schema_name":"sys","schema_owner":null,"default_character_set_name":null,"default_collation_name":null},</span><span class="go">{"schema_name":"test","schema_owner":null,"default_character_set_name":null,"default_collation_name":null}</span><span class="go">]</span><span class="gp">$</span>
Lets try a Drupal specific example next. Our REST API allows you to retrieve an entire table group in 1 request. So let’s say I wanted to get all information for a certain user (I pretty-printed the JSON in the output below so if you run this you will need to format the output):
<span class="gp">$</span> curl -X GET -H <span class="s2">"Content-Type: application/json"</span> http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/drupal.users/1<span class="go">[</span><span class="go"> {</span><span class="go"> "uid": 1,</span><span class="go"> "name": "posulliv",</span><span class="go"> "pass": "$S$DPV31LZyFWJmJ.Fcj6IRyjb/RFMyQQtE87gsad7cavgnH3fw0GHA",</span><span class="go"> "mail": "posullivan@akiban.com",</span><span class="go"> "theme": "",</span><span class="go"> "signature": "",</span><span class="go"> "signature_format": null,</span><span class="go"> "created": 1355345142,</span><span class="go"> "access": 1355762571,</span><span class="go"> "login": 1355345211,</span><span class="go"> "status": 1,</span><span class="go"> "timezone": "America/New_York",</span><span class="go"> "language": "",</span><span class="go"> "picture": 0,</span><span class="go"> "init": "posullivan@akiban.com",</span><span class="go"> "data": "YjowOw==",</span><span class="go"> "drupal.authmap": [],</span><span class="go"> "drupal.sessions": [</span><span class="go"> {</span><span class="go"> "uid": 1,</span><span class="go"> "sid": "jq57PowPwDK1CuKBpC56oqt_PsbwWNF4av97BuQqr6I",</span><span class="go"> "ssid": "",</span><span class="go"> "hostname": "75.147.9.1",</span><span class="go"> "timestamp": 1355762574,</span><span class="go"> "cache": 0,</span><span class="go"> "session": "YmF0Y2hlc3xhOjE6e2k6MTtiOjE7fWF1dGhvcml6ZV9maWxldHJhbnNmZXJfaW5mb3xhOjE6e3M6MzoiZnRwIjthOjU6e3M6NToidGl0bGUiO3M6MzoiRlRQIjtzOjU6ImNsYXNzIjtzOjE1OiJGaWxlVHJhbnNmZXJGVFAiO3M6NDoiZmlsZSI7czo3OiJmdHAuaW5jIjtzOjk6ImZpbGUgcGF0aCI7czoyMToiaW5jbHVkZXMvZmlsZXRyYW5zZmVyIjtzOjY6IndlaWdodCI7aTowO319YXV0aG9yaXplX29wZXJhdGlvbnxhOjQ6e3M6ODoiY2FsbGJhY2siO3M6Mjg6InVwZGF0ZV9hdXRob3JpemVfcnVuX2luc3RhbGwiO3M6NDoiZmlsZSI7czozNToibW9kdWxlcy91cGRhdGUvdXBkYXRlLmF1dGhvcml6ZS5pbmMiO3M6OToiYXJndW1lbnRzIjthOjM6e3M6NzoicHJvamVjdCI7czo1OiJkZXZlbCI7czoxMjoidXBkYXRlcl9uYW1lIjtzOjEzOiJNb2R1bGVVcGRhdGVyIjtzOjk6ImxvY2FsX3VybCI7czozNzoiL3RtcC91cGRhdGUtZXh0cmFjdGlvbi1kOWU4MTUzOS9kZXZlbCI7fXM6MTA6InBhZ2VfdGl0bGUiO3M6MTQ6IlVwZGF0ZSBtYW5hZ2VyIjt9bWVzc2FnZXN8YToxOntzOjU6ImVycm9yIjthOjI6e2k6MDtzOjI3NToiPGVtIGNsYXNzPSJwbGFjZWhvbGRlciI+V2FybmluZzwvZW0+OiBhcnJheV9rZXlfZXhpc3RzKCkgZXhwZWN0cyBwYXJhbWV0ZXIgMiB0byBiZSBhcnJheSwgbnVsbCBnaXZlbiBpbiA8ZW0gY2xhc3M9InBsYWNlaG9sZGVyIj50aGVtZV9pbWFnZV9mb3JtYXR0ZXIoKTwvZW0+IChsaW5lIDxlbSBjbGFzcz0icGxhY2Vob2xkZXIiPjYwNTwvZW0+IG9mIDxlbSBjbGFzcz0icGxhY2Vob2xkZXIiPi92YXIvd3d3L2RydXBhbC9tb2R1bGVzL2ltYWdlL2ltYWdlLmZpZWxkLmluYzwvZW0+KS4iO2k6MTtzOjI3NToiPGVtIGNsYXNzPSJwbGFjZWhvbGRlciI+V2FybmluZzwvZW0+OiBhcnJheV9rZXlfZXhpc3RzKCkgZXhwZWN0cyBwYXJhbWV0ZXIgMiB0byBiZSBhcnJheSwgbnVsbCBnaXZlbiBpbiA8ZW0gY2xhc3M9InBsYWNlaG9sZGVyIj50aGVtZV9pbWFnZV9mb3JtYXR0ZXIoKTwvZW0+IChsaW5lIDxlbSBjbGFzcz0icGxhY2Vob2xkZXIiPjYwNTwvZW0+IG9mIDxlbSBjbGFzcz0icGxhY2Vob2xkZXIiPi92YXIvd3d3L2RydXBhbC9tb2R1bGVzL2ltYWdlL2ltYWdlLmZpZWxkLmluYzwvZW0+KS4iO319"</span><span class="go"> }</span><span class="go"> ],</span><span class="go"> "drupal.shortcut_set_users": [],</span><span class="go"> "drupal.users_roles": [</span><span class="go"> {</span><span class="go"> "uid": 1,</span><span class="go"> "rid": 3</span><span class="go"> }</span><span class="go"> ],</span><span class="go"> "drupal.watchdog": [</span><span class="go"> {</span><span class="go"> "wid": 160662,</span><span class="go"> "uid": 1,</span><span class="go"> "type": "php",</span><span class="go"> "message": "JXR5cGU6ICFtZXNzYWdlIGluICVmdW5jdGlvbiAobGluZSAlbGluZSBvZiAlZmlsZSku",</span><span class="go"> "variables": "YTo2OntzOjU6IiV0eXBlIjtzOjc6Ildhcm5pbmciO3M6ODoiIW1lc3NhZ2UiO3M6NjI6ImFycmF5X2tleV9leGlzdHMoKSBleHBlY3RzIHBhcmFtZXRlciAyIHRvIGJlIGFycmF5LCBudWxsIGdpdmVuIjtzOjk6IiVmdW5jdGlvbiI7czoyMzoidGhlbWVfaW1hZ2VfZm9ybWF0dGVyKCkiO3M6NToiJWZpbGUiO3M6NDU6Ii92YXIvd3d3L2RydXBhbC9tb2R1bGVzL2ltYWdlL2ltYWdlLmZpZWxkLmluYyI7czo1OiIlbGluZSI7aTo2MDU7czoxNDoic2V2ZXJpdHlfbGV2ZWwiO2k6NDt9",</span><span class="go"> "severity": 4,</span><span class="go"> "link": "0",</span><span class="go"> "location": "aHR0cDovL2VjMi01MC0xOS0yOC0yNy5jb21wdXRlLTEuYW1hem9uYXdzLmNvbS9kcnVwYWwv",</span><span class="go"> "referer": "aHR0cDovL2VjMi01MC0xOS0yOC0yNy5jb21wdXRlLTEuYW1hem9uYXdzLmNvbS9kcnVwYWwv",</span><span class="go"> "hostname": "24.61.45.238",</span><span class="go"> "timestamp": 1355406786</span><span class="go"> }</span><span class="go"> ]</span><span class="go"> }</span><span class="go">]</span><span class="gp">$</span>
We also support multi-get so you can retrieve a number of table groups in a single REST API call. For example, lets say I want to get information on 2 users:
<span class="gp">$</span> curl -X GET -H <span class="s2">"Content-Type: application/json"</span> <span class="s2">"http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/drupal.users/11467;10503"</span><span class="go">[</span><span class="go"> {</span><span class="go"> "uid": 11467,</span><span class="go"> "name": "clibriprofr",</span><span class="go"> "pass": "",</span><span class="go"> "mail": "clibriprofr@default",</span><span class="go"> "theme": "",</span><span class="go"> "signature": "",</span><span class="go"> "signature_format": null,</span><span class="go"> "created": 1355360324,</span><span class="go"> "access": 0,</span><span class="go"> "login": 0,</span><span class="go"> "status": 1,</span><span class="go"> "timezone": null,</span><span class="go"> "language": "und",</span><span class="go"> "picture": 11463,</span><span class="go"> "init": "",</span><span class="go"> "data": null,</span><span class="go"> "drupal.authmap": [],</span><span class="go"> "drupal.sessions": [],</span><span class="go"> "drupal.shortcut_set_users": [],</span><span class="go"> "drupal.users_roles": [],</span><span class="go"> "drupal.watchdog": []</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "uid": 10503,</span><span class="go"> "name": "uuslosuwr",</span><span class="go"> "pass": "",</span><span class="go"> "mail": "uuslosuwr@default",</span><span class="go"> "theme": "",</span><span class="go"> "signature": "",</span><span class="go"> "signature_format": null,</span><span class="go"> "created": 1355360324,</span><span class="go"> "access": 0,</span><span class="go"> "login": 0,</span><span class="go"> "status": 1,</span><span class="go"> "timezone": null,</span><span class="go"> "language": "und",</span><span class="go"> "picture": 10499,</span><span class="go"> "init": "",</span><span class="go"> "data": null,</span><span class="go"> "drupal.authmap": [],</span><span class="go"> "drupal.sessions": [],</span><span class="go"> "drupal.shortcut_set_users": [],</span><span class="go"> "drupal.users_roles": [],</span><span class="go"> "drupal.watchdog": []</span><span class="go"> }</span><span class="go">]</span><span class="gp">$</span>
Our REST API also supports aribtrary SQL queries being executed and results being returned as JSON. Lets try a simple example first:
<span class="gp">$</span> curl -X GET -H <span class="s2">"Content-Type: application/json"</span> <span class="s2">"http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/query?q=select%20count(*)%20from%20drupal.comment"</span><span class="go">[</span><span class="go">{"_SQL_COL_1":252462}</span><span class="go">]</span><span class="gp">$</span>
Another example of executing arbitrary SQL queries through our REST API with a more complex query follows. The query we will use for this example is:
<span class="k">SELECT</span> <span class="k">c</span><span class="p">.</span><span class="o">*</span> <span class="k">FROM</span> <span class="n">drupal</span><span class="p">.</span><span class="k">comment</span> <span class="k">c</span> <span class="k">INNER</span> <span class="k">JOIN</span> <span class="n">drupal</span><span class="p">.</span><span class="n">node</span> <span class="n">n</span> <span class="k">ON</span> <span class="n">n</span><span class="p">.</span><span class="n">nid</span> <span class="o">=</span> <span class="k">c</span><span class="p">.</span><span class="n">nid</span> <span class="k">WHERE</span> <span class="p">(</span> <span class="k">c</span><span class="p">.</span><span class="n">status</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">)</span> <span class="k">AND</span> <span class="p">(</span> <span class="n">n</span><span class="p">.</span><span class="n">status</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">)</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="k">c</span><span class="p">.</span><span class="n">created</span> <span class="k">DESC</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="n">cid</span> <span class="k">DESC</span> <span class="k">LIMIT</span> <span class="mi">10</span> <span class="k">offset</span> <span class="mi">0</span>
Running this query through our REST API and the result (again, nicely formatted) looks like:
<span class="go">curl -X GET -H "Content-Type: application/json" "http://ec2-50-19-28-27.compute-1.amazonaws.com:8091/api/query?q=SELECT%20c.*%20FROM%20drupal.comment%20c%20INNER%20JOIN%20drupal.node%20n%20ON%20n.nid%20=%20c.nid%20WHERE%20(c.status%20=%201)%20AND%20(n.status%20=%201)%20ORDER%20BY%20c.created%20DESC,%20c.cid%20DESC%20LIMIT%2010%20OFFSET%200"</span><span class="go">[</span><span class="go"> {</span><span class="go"> "cid": 304562,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93450,</span><span class="go"> "uid": 1,</span><span class="go"> "subject": "this is a test comment",</span><span class="go"> "hostname": "75.147.9.1",</span><span class="go"> "created": 1355418376,</span><span class="go"> "changed": 1355418376,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01/",</span><span class="go"> "name": "posulliv",</span><span class="go"> "mail": "",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304561,</span><span class="go"> "pid": 304558,</span><span class="go"> "nid": 93451,</span><span class="go"> "uid": 3636,</span><span class="go"> "subject": "Defui Enim Gemino Luctus Occuro Paulatim",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01.00/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304560,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93451,</span><span class="go"> "uid": 3633,</span><span class="go"> "subject": "Abdo Ea Sudo Veniam Vulputate",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "03/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304559,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93451,</span><span class="go"> "uid": 3651,</span><span class="go"> "subject": "Defui Euismod Letalis Nisl Utinam Vicis",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "02/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304558,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93451,</span><span class="go"> "uid": 3657,</span><span class="go"> "subject": "Similis Te",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304557,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93448,</span><span class="go"> "uid": 3630,</span><span class="go"> "subject": "Loquor Modo Ut",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "02/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304556,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93448,</span><span class="go"> "uid": 3648,</span><span class="go"> "subject": "Abico Conventio Elit Quis",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304555,</span><span class="go"> "pid": 0,</span><span class="go"> "nid": 93447,</span><span class="go"> "uid": 3646,</span><span class="go"> "subject": "Dolor Immitto Metuo Veniam",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "04/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304554,</span><span class="go"> "pid": 304553,</span><span class="go"> "nid": 93447,</span><span class="go"> "uid": 3633,</span><span class="go"> "subject": "Defui Et Pertineo Premo Usitas",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01.00.00/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> },</span><span class="go"> {</span><span class="go"> "cid": 304553,</span><span class="go"> "pid": 304550,</span><span class="go"> "nid": 93447,</span><span class="go"> "uid": 3655,</span><span class="go"> "subject": "Amet Gravis Inhibeo Roto Torqueo",</span><span class="go"> "hostname": "127.0.0.1",</span><span class="go"> "created": 1355369527,</span><span class="go"> "changed": 1355369527,</span><span class="go"> "status": 1,</span><span class="go"> "thread": "01.00/",</span><span class="go"> "name": "devel generate",</span><span class="go"> "mail": "devel_generate@example.com",</span><span class="go"> "homepage": "",</span><span class="go"> "language": "und"</span><span class="go"> }</span><span class="go">]</span><span class="gp">$</span>
Finally, I’d like to mention we have a client for node.js
that can be used with our REST interface. To get information on the schemas in this server and the grouping in the drupal schema, some code using this client would look as follows:
<span class="err">#</span><span class="o">!</span><span class="err">/usr/bin/env coffee</span><span class="nx">ak</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./lib/akiban_rest.js'</span><span class="p">)</span><span class="nx">_</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'underscore'</span><span class="p">)</span><span class="nx">log</span> <span class="o">=</span> <span class="p">(</span><span class="nx">msg</span><span class="p">)</span> <span class="o">-></span> <span class="p">()</span> <span class="o">-></span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"========"</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">msg</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"--------"</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">error</span> <span class="nx">_</span><span class="p">(</span><span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">body</span><span class="p">).</span><span class="nx">forEach</span> <span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="o">-></span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">arguments</span><span class="p">)</span> <span class="k">if</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">error</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"--------"</span><span class="p">)</span><span class="nx">x</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ak</span><span class="p">.</span><span class="nx">AkibanClient</span><span class="p">()</span><span class="nx">x</span><span class="p">.</span><span class="nx">version</span><span class="p">(</span><span class="nx">log</span><span class="p">(</span><span class="s1">'the server version is'</span><span class="p">))</span><span class="nx">x</span><span class="p">.</span><span class="nx">schemata</span><span class="p">(</span><span class="nx">log</span><span class="p">(</span><span class="s1">'and these are all the schemata'</span><span class="p">))</span><span class="nx">x</span><span class="p">.</span><span class="nx">groups</span><span class="p">(</span><span class="s1">'drupal'</span><span class="p">,</span> <span class="nx">log</span><span class="p">(</span><span class="s1">'all groups in the drupal schema'</span><span class="p">))</span>
The above can be run with the coffee
command like so: coffeedrupal.coffee
.
To retrieve a certain node with this client, the code would look like:
<span class="err">#</span><span class="o">!</span><span class="err">/usr/bin/env coffee</span><span class="nx">ak</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./lib/akiban_rest.js'</span><span class="p">)</span><span class="nx">_</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'underscore'</span><span class="p">)</span><span class="nx">log</span> <span class="o">=</span> <span class="p">(</span><span class="nx">msg</span><span class="p">)</span> <span class="o">-></span> <span class="p">()</span> <span class="o">-></span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"========"</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">msg</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"--------"</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">error</span> <span class="nx">_</span><span class="p">(</span><span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">body</span><span class="p">).</span><span class="nx">forEach</span> <span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="o">-></span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">arguments</span><span class="p">)</span> <span class="k">if</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">error</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"--------"</span><span class="p">)</span><span class="nx">x</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ak</span><span class="p">.</span><span class="nx">AkibanClient</span><span class="p">()</span><span class="nx">x</span><span class="p">.</span><span class="nx">get</span> <span class="s1">'drupal'</span><span class="p">,</span> <span class="s1">'node'</span><span class="p">,</span> <span class="mi">2054</span><span class="p">,</span> <span class="p">(</span><span class="nx">res</span><span class="p">)</span> <span class="o">-></span> <span class="nx">log</span><span class="p">(</span><span class="s1">'retrieving nid 2054'</span><span class="p">)(</span><span class="nx">res</span><span class="p">)</span>
Running the above example results in output like:
<span class="gp">$</span> coffee drupal.coffee <span class="go">========</span><span class="go">retrieving nid 2054</span><span class="go">--------</span><span class="go">{ nid: 2054,</span><span class="go"> vid: 2054,</span><span class="go"> type: 'page',</span><span class="go"> language: 'und',</span><span class="go"> title: 'Eros Iriure Pertineo Refoveo Roto Utrum',</span><span class="go"> uid: 3661,</span><span class="go"> status: 1,</span><span class="go"> created: 1355369527,</span><span class="go"> changed: 1355369527,</span><span class="go"> comment: 0,</span><span class="go"> promote: 1,</span><span class="go"> sticky: 0,</span><span class="go"> tnid: 0,</span><span class="go"> translate: 0,</span><span class="go"> 'drupal.comment': [],</span><span class="go"> 'drupal.history': [],</span><span class="go"> 'drupal.node_access': [],</span><span class="go"> 'drupal.node_comment_statistics': </span><span class="go"> [ { nid: 2054,</span><span class="go"> cid: 0,</span><span class="go"> last_comment_timestamp: 1355369527,</span><span class="go"> last_comment_name: null,</span><span class="go"> last_comment_uid: 3656,</span><span class="go"> comment_count: 0 } ],</span><span class="go"> 'drupal.node_revision': </span><span class="go"> [ { nid: 2054,</span><span class="go"> vid: 2056,</span><span class="go"> uid: 1,</span><span class="go"> title: 'Ad Si Suscipere',</span><span class="go"> log: '',</span><span class="go"> timestamp: 1355369527,</span><span class="go"> status: 1,</span><span class="go"> comment: 0,</span><span class="go"> promote: 1,</span><span class="go"> sticky: 0 } ],</span><span class="go"> 'drupal.search_node_links': [] }</span><span class="go">--------</span>
Thats about it for this post showing off our REST access. As usual, comments are very much welcome and feel free to ping me on twitter if you would like to learn more about Akiban.