How to define a callback for an URI?

You can use add_feed( $url, $callback ). Despite its name it sends a text/html Content-Type.

Basic example:

add_action( 'init', 'wpse_50841_register_extra_page' );

function wpse_50841_register_extra_page()
{
    add_feed( 'wpse50841', 'wpse_50841_callback' );
}

function wpse_50841_callback()
{
    print '<p>It works!</p>';
}

Visit the permalink settings page once to refresh the rewrite cache, and go to example.com/wpse50841/ or example.com/?feed=wpse50841 to see your code in action.

tech