Move page-generating functions into include file, and refactor repeated code

Migrated issue

Reported by: jhodgdon

I think all of the functions related to generating pages for the API module should probably be in an api.pages.inc file. This is fairly standard across Drupal core and contributed modules.