Q:

Drupal - fetch body text of a node via URL?

I'm trying to create a function to retrieve and display just the Body field of a Drupal node, based on a given URL.
Currently, I've extended the functionality of the standard Drupal RSS to do a detection method.  This will happen if you enter the following url:
http://mysite.com/rss.xml/page=54
That last part is critical - it tells what node ID to load from.  As far as code goes, I've modified the node_feed() function in /modules/node/node.module to do the following:
if (stristr($nids, 'page=') !== FALSE) {
 $nid = substr($nids, stripos($nids, 'page=') + 5);
 $result = NULL;

 if ((string)(int)$nid === $nid) {
  $result = db_result(db_query("SELECT `nid` FROM {node} WHERE `nid` = %s AND `type` =  'flashnode'", $nid));
 }

 if ($result) {
   $item = node_load($result);
   print($item->body);
 }
 exit;
}

While this works, we're worried about it for two reasons:
1) Do the results cache?  This is a very heavy-load page that will be called a lot.
2) Is there an "official" way to do this?  One that uses modules with caching, instead of a semi-hacky workaround?
Thanks in advance for any guidance.
-Tom

A:

You should definitely not be hacking apart the RSS feed in order to create a URL that returns a node's body. You should create a very simple custom module: http://drupal.org/developing/modules
The Drupal module system is lets you set up a url so that something like /fetch_body/1234 calls the fetch_body() function with $nid=1234 as the parameter. As for caching, you have a lot of options in your custom module. The most obvious would be to use cache_get() and cache_set() to do simple caching on your own based on the node ID.
What version of Drupal are you using? I would highly recommend the book Pro Drupal Development, just make sure to get the edition that matches your drupal version.

