Create your own API Site in Drupal 6
These instructions are for installing the API Module in a Drupal 6 environment. Please note the API module can parse any documented Drupal code, including contributed modules. This means the code you parse and the code you use to run your site need not necessarily be the same. In fact, it may also be a good idea to keep the code you are parsing outside of the site running the API module. These instructions are made with that assumption.
Step 1: Install and Setup Site
These are the basics steps for getting your site going.
- Download Drupal 6 at: http://drupal.org/project/drupal
- Install Drupal. See: http://drupal.org/getting-started/install
- Download and Install Job Queue module, which is a dependency of API module: http://drupal.org/project/job_queue
- Download and Install API module: http://drupal.org/project/api
- Change permissions for API module as needed at:
admin/user/permissions
Step 2: Set-up Code "Repositories"
This step involves creating a place to store the code you want to parse. We will go through instructions for a Drupal 6 code base, but this can be applied to any version of Drupal, and contributed modules and themes. This also includes getting the supplemental developer documentation from CVS.
- Create a place for your code to go:
mkdir -p /path/to/your/code/repos/
cd /path/to/your/code/repos/ - Get the most recent version of Drupal 6 code base (see http://drupal.org/node/320 for more information). Note we are naming our directory drupal-6. We could also get any version of Drupal 6 here.
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -r DRUPAL-6 -d drupal-6 drupal - Get the extra developer documentation directly from CVS. This is the part of the documentation that brings pieces together and provides different subjects. It also provides the main front page at http://api.drupal.org, different groups and subject, and all the different documentation for the hooks in core, which are pretty useful.
Go to the Drupal root of our Drupal 6 repo.
cd /path/to/your/code/repos/drupal-6Checkout the developer documentation from CVS. Note that this command gets the Drupal 6 version:
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--1 -d developer-docs contributions/docs/developer
Step 3: Set-up API Module and Index Code
This section will tell you how to use the API module interface and how to index the code in the repo we set up above. The term "branch" is used here because of its association of use with the different Drupal branches. In reality, a "branch" is really just sets of code.
- Go to the site you set up in Step 1, and add a new Branch at:
admin/settings/api/branches/new. Fill out the form with the following values:
- URL Label
- This is the string that will be used in the URL for the documentation that is created. I suggest: drupal-6
- Page Label
- This is the actual title of the branch of code. It will be used in tabs and blocks. I suggest: Drupal 6
- Directories
- This is a list of absolute paths to the place(s) where your code is. This is where we put in the value from Step 2. /path/to/your/code/repos/drupal-6
Click Save Branch.
Re-indexing is done through cron after every branch save. The API module also uses the Job Queue module so that cron will do as much as it can each time. You can either wait for cron to run a few times, or run cron manually a few times at:
admin/reports/status/run-cron - Go to your new api documentation at:
api. The content should resemble the content at http://api.drupal.org.
Step 4: Some Extra Flair
Some extra steps if you want.
- Enable the API blocks at:
admin/build/blocks - Index PHP functions at:
admin/settings/api/php - Use Steps 2 and 3 to create a Branch for Drupal 5.
- Use Steps 2 and 3 to create a Branch for Drupal 6 Contributed Modules that you use. Or, simply include contributed modules into your Drupal 6 code base that is already being indexed.

Since this page doesn't cover
Since this page doesn't cover how to add contributed modules to your api site I'll try to explain what I did. If someone knows a better way to do it please let us know in the comments.
I created a new folder under my repos directory: /path/to/repos/contributions. Then I cd to that directory and did:
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--2 -d views contributions/modules/viewsTo get the version 2 of views.
I added a new branch on the api settings with the path to the contributions. Finally I just copied the file index.php that I found in the contributions/docs/developer to the to /path/to/repos/contributions and made some changes to the text according to the README that you find in the api module.
Finally I had to move the contributions/docs/developer to the root of my site and not only to the drupal-6 directory inside my repos directory. I don't really know if this is correct.
The last step is to run cron like a hundred times :)
Luis
run cron multiple times
I add to run the cron hundred times so I thought this shell script could be useful. I wish the api module (or job queue) had a more optimized way of parsing all the files.
# run cron multiple timesfor i in $(seq 100)
do
wget -O - -q -t 1 http://localhost/d6api/cron.php
done
Another shell script
I'm using Mac OS X 10.5.8 and MAMP for local testing. Because I couldn't use the script scor posted above, I did some search and figured out another script.
for (( i=0 ; i<300 ; i++ ))do
curl --silent --compressed http://localhost:8888/drupal-API/cron.php
done
Change the number in the first line ( i<300 ) to any number of times you want to run cron.
Here's a perl one-liner you
Here's a perl one-liner you can run from the commandline:
perl -e 'while (1) { print qx[curl http://YOURSITE/cron.php]; sleep 15;}'Obviously this runs for ever; just check the job queue page after a while to see how many jobs are left and CTRL-C kill the script.