Accessing Correct Database to Create REST API Endpoint

You can access another database using the wpdb class and its associated methods. You will need to instantiate a new connection to the other database using the appropriate credentials. Here is the basic code to set up the new connection and query the database:

$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("<your SQL query here>");

Replace the parameters to the wpdb() method as required and construct the necessary query for get_results().