Core function to check if a rest namespace exists

You can use the WP_REST_Server::get_namespaces() method.

For instance.

$exists = in_array( 'ns/v1', rest_get_server()->get_namespaces() );